flutterTemplate static method

Future<void> flutterTemplate()

Implementation

static Future<void> flutterTemplate() async {
  final logger = Logger();

  final projectName = InputService.getValidatedInput(
      consoleMessage: Constants.kEnterProjectName,
      errorMessage: Constants.kEnterValidProjectName,
      functionValidator: Validator.isValidProjectName
  );

  final path = DirectoryService.choosePath();
  final projectPath = '$path/$projectName';

  final appName = InputService.getValidatedInput(
      consoleMessage: Constants.kEnterAppName,
      errorMessage: Constants.kInvalidValue,
      functionValidator: Validator.isValidAppName
  );

  final appOrgBundle = InputService.getValidatedInput(
      consoleMessage: Constants.kEnterAppOrgBundle,
      errorMessage: Constants.kInvalidValue,
      functionValidator: Validator.isValidOrgBundle
  );

  final projectDescription = InputService.getValidatedInput(
    consoleMessage: Constants.kEnterProjectDescription,
    errorMessage: Constants.kInvalidValue
  );

  final listPlatforms = logger.chooseAny(
      Constants.kChoosePlatform,
      choices: <String>['ios', 'android', 'windows', 'linux', 'macos', 'web'],
      defaultValues: <String>['ios', 'android', 'windows', 'linux', 'macos', 'web']
  );
  final platforms = listPlatforms.join(',');

  final process = Process.runSync(
    'flutter',
    <String>[
      'create',
      '--empty',
      '--project-name=$projectName',
      '--description=$projectDescription',
      '--org=$appOrgBundle',
      '--platforms=$platforms',
      projectPath
    ],
    runInShell: true
  );

  if (process.exitCode != 0) {
    Console.writeLine(dcli.red('❌  Failed to create Flutter project: ${process.stderr}'));
    exit(1);
  }

  await FileModifier.changeAppName(
    projectName: projectName ?? 'example_app',
    appName: appName ?? 'Example App',
    path: projectPath
  );

  final directories = [
    'assets/fonts',
    'assets/icons',
    'assets/images',
    'assets/launcher_icon',
    'assets/splash',
    'lib/api/dto',
    'lib/api/requests',
    'lib/init',
    'lib/features',
    'lib/core',
    'lib/repositories',
    'lib/router',
    'lib/ui/images',
    'lib/ui/icons',
    'lib/ui/theme',
    'lib/ui/widgets',
    'lib/utils/mixin',
    'lib/utils/extensions',
    'docs'
  ];

  DirectoryService.buildStructure(projectPath: projectPath, directories: directories);

  Console.writeLine(dcli.green('✅  The project was created successfully!'));
}