run method

  1. @override
Future<int> run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future<int> run() async {
  return handleRuntimeErrors(() async {
    final flutterVersion = await FlutterService.version();
    final dartVersion = DartService.version();

    header('Create', message: description);
    info(
      'Default values are indicated by '.cGray + theme.colors.success('*'),
    );
    line();
    line();
    final ProjectType projectType =
        selectProjectType(flutterVersion, dartVersion);
    final isFlutter = projectType == ProjectType.flutter;
    final isDart = projectType == ProjectType.dart;

    if (isFlutter) {
      line();
      final template = selectFlutterTemplate();
      line();
      final projectName = promptProjectName();
      line();
      final projectParentDir = promptProjectParentDir(projectName);
      line();
      final shouldOverwrite = selectShouldOverwrite(
        projectParentDir,
        projectName,
      );
      line();
      final projectDescription = promptProjectDescription();
      line();
      final organization = promptProjectOrganization();
      List<PlatformType> supportedPlatforms = [];
      if (template == FlutterProjectTemplate.app ||
          template == FlutterProjectTemplate.appEmpty ||
          template == FlutterProjectTemplate.plugin) {
        line();
        supportedPlatforms = selectSupportedPlatforms();
      }
      AndroidLanguage? androidLanguage;
      if (supportedPlatforms.contains(PlatformType.Android)) {
        line();
        androidLanguage = selectAndroidLanguage();
      }
      line();
      final shouldRunPubGet = selectShouldRunPubGet();
      line();
      final isOfflineMode = selectIsOfflineMode();
      final config = FlutterProjectConfig(
        projectName: projectName,
        projectParentDir: projectParentDir,
        template: template.value,
        isEmptyApp: template == FlutterProjectTemplate.appEmpty,
        shouldOverwrite: shouldOverwrite,
        description: projectDescription,
        organization: organization,
        platforms:
            supportedPlatforms.map((p) => p.name.toLowerCase()).toList(),
        androidLanguage: androidLanguage?.name.toLowerCase(),
        shouldRunPubGet: shouldRunPubGet,
        isOfflineMode: isOfflineMode,
      );
      promptCommandConfirmation(config);
      line();
      final createTask = CreateFlutterProjectTask(config);
      return await runCreateTask(createTask, config.projectDir);
    } else if (isDart) {
      line();
      final template = selectDartTemplate();
      line();
      final projectName = promptProjectName();
      line();
      final projectParentDir = promptProjectParentDir(projectName);
      line();
      final shouldForce = selectShouldOverwrite(
        projectParentDir,
        projectName,
      );
      line();
      final shouldRunPubGet = selectShouldRunPubGet();
      final config = DartProjectConfig(
        projectName: projectName,
        projectParentDir: projectParentDir,
        template: template.value,
        shouldForce: shouldForce,
        shouldRunPubGet: shouldRunPubGet,
      );
      promptCommandConfirmation(config);
      line();
      final createTask = CreateDartProjectTask(config);
      return await runCreateTask(createTask, config.projectDir);
    }

    return ExitCode.success.code;
  });
}