@@ -65,6 +65,12 @@ class CreateCommand extends CreateBase {
65
65
'https://api.flutter.dev/flutter/widgets/SingleChildScrollView-class.html' ,
66
66
valueHelp: 'id' ,
67
67
);
68
+ argParser.addFlag (
69
+ 'empty' ,
70
+ abbr: 'e' ,
71
+ help: 'Specifies creating using an application template with a main.dart that is minimal, '
72
+ 'including no comments, as a starting point for a new application. Implies "--template=app".' ,
73
+ );
68
74
argParser.addOption (
69
75
'list-samples' ,
70
76
help: 'Specifies a JSON output file for a listing of Flutter code samples '
@@ -191,9 +197,17 @@ class CreateCommand extends CreateBase {
191
197
return FlutterCommandResult .success ();
192
198
}
193
199
200
+ if (argResults! .wasParsed ('empty' ) && argResults! .wasParsed ('sample' )) {
201
+ throwToolExit (
202
+ 'Only one of --empty or --sample may be specified, not both.' ,
203
+ exitCode: 2 ,
204
+ );
205
+ }
206
+
194
207
validateOutputDirectoryArg ();
195
208
String ? sampleCode;
196
209
final String ? sampleArgument = stringArg ('sample' );
210
+ final bool emptyArgument = boolArg ('empty' ) ?? false ;
197
211
if (sampleArgument != null ) {
198
212
final String ? templateArgument = stringArg ('template' );
199
213
if (templateArgument != null && stringToProjectType (templateArgument) != FlutterProjectType .app) {
@@ -299,6 +313,7 @@ class CreateCommand extends CreateBase {
299
313
flutterRoot: flutterRoot,
300
314
withPlatformChannelPluginHook: generateMethodChannelsPlugin,
301
315
withFfiPluginHook: generateFfiPlugin,
316
+ withEmptyMain: emptyArgument,
302
317
androidLanguage: stringArgDeprecated ('android-language' ),
303
318
iosLanguage: stringArgDeprecated ('ios-language' ),
304
319
iosDevelopmentTeam: developmentTeam,
@@ -411,11 +426,15 @@ class CreateCommand extends CreateBase {
411
426
);
412
427
}
413
428
if (sampleCode != null ) {
414
- generatedFileCount += _applySample (relativeDir, sampleCode);
429
+ _applySample (relativeDir, sampleCode);
430
+ }
431
+ if (sampleCode != null || emptyArgument) {
432
+ generatedFileCount += _removeTestDir (relativeDir);
415
433
}
416
434
globals.printStatus ('Wrote $generatedFileCount files.' );
417
435
globals.printStatus ('\n All done!' );
418
- final String application = sampleCode != null ? 'sample application' : 'application' ;
436
+ final String application =
437
+ '${emptyArgument ? 'empty' : '' }${sampleCode != null ? 'sample' : '' } application' ;
419
438
if (generatePackage) {
420
439
final String relativeMainPath = globals.fs.path.normalize (globals.fs.path.join (
421
440
relativeDirPath,
@@ -657,10 +676,13 @@ Your $application code is in $relativeAppMain.
657
676
// documentation website in sampleCode. Returns the difference in the number
658
677
// of files after applying the sample, since it also deletes the application's
659
678
// test directory (since the template's test doesn't apply to the sample).
660
- int _applySample (Directory directory, String sampleCode) {
679
+ void _applySample (Directory directory, String sampleCode) {
661
680
final File mainDartFile = directory.childDirectory ('lib' ).childFile ('main.dart' );
662
681
mainDartFile.createSync (recursive: true );
663
682
mainDartFile.writeAsStringSync (sampleCode);
683
+ }
684
+
685
+ int _removeTestDir (Directory directory) {
664
686
final Directory testDir = directory.childDirectory ('test' );
665
687
final List <FileSystemEntity > files = testDir.listSync (recursive: true );
666
688
testDir.deleteSync (recursive: true );
0 commit comments