run method

  1. @override
void run()
override

Runs this command.

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

Implementation

@override
void run() async {
  var projectName = argResults?['projectName'];
  var iosBundleId = argResults?['bundleId'];
  var androidApplicationId = argResults?['applicationId'];

  projectName ??= XInput.askValue(
    'Enter Project Name:',
    'my_dream_project',
    validators: [
      ProjectNameValidator(),
    ],
  );

  iosBundleId ??= XInput.askValue(
    'Enter IOS Bundle Id:',
    'sa.bond.com',
    validators: [
      BundleIdOrApplicationIdValidator(isIOS: true),
    ],
  );

  androidApplicationId ??= XInput.askValue(
    'Enter Android Application Id:',
    'sa.bond.com',
    validators: [
      BundleIdOrApplicationIdValidator(isIOS: false),
    ],
  );

  final appName = projectName.replaceAll(' ', '_').toLowerCase();

  final projectPath = '${Directory.current.path}/$projectName';
  ConsolePrinter.info('Creating a "$appName" project at $projectPath');

  final projectDirectory = await ProjectCloningTask(
    projectName: projectName,
  ).run();

  if (Platform.isMacOS) {
    await SetupIosProjectTask(
      iosManager: IosManager(
        Directory(
          '${projectDirectory.path}/ios',
        ),
      ),
      bundleId: iosBundleId,
      appName: appName,
    ).run();
  } else {
    ConsolePrinter.warning('skip setup ios ios project for non mac os.');
  }

  await SetupAndroidProjectTask(
    androidManager: AndroidManager(
      Directory('${projectDirectory.path}/android'),
    ),
    appName: appName,
    applicationId: androidApplicationId,
  ).run();

  await SetupFlutterProjectTask(
    flutterManager: FlutterManager(
      projectDirectory,
      printToConsole: false,
    ),
    appName: appName,
    projectName: projectName,
  ).run();
}