starter function

Future<void> starter(
  1. List<String> args
)

Implementation

Future<void> starter(List<String> args) async {
  List<String> params = args.toList();

  String org = '';
  String android = '';
  String ios = '';
  String name = '';
  String template = 'provider';

  List<String> fcargs = [];

  if (params.contains('--p')) {
    int idx = params.indexOf('--p');
    name = params[idx + 1];
    fcargs.add('--project-name');
    fcargs.add(name);
    params.removeAt(idx);
    params.removeAt(idx);
  }

  if (params.contains('--org')) {
    int idx = params.indexOf('--org');
    org = params[idx + 1];
    fcargs.add('--org');
    fcargs.add(org);
    params.removeAt(idx);
    params.removeAt(idx);
  }

  if (params.contains('--a')) {
    int idx = params.indexOf('--a');
    android = params[idx + 1];
    fcargs.add('--android-language');
    fcargs.add(android);
    params.removeAt(idx);
    params.removeAt(idx);
  }

  if (params.contains('--i')) {
    int idx = params.indexOf('--i');
    ios = params[idx + 1];
    fcargs.add('--ios-language');
    fcargs.add(ios);
    params.removeAt(idx);
    params.removeAt(idx);
  }

  if (params.contains('--t')) {
    int idx = params.indexOf('--t');
    template = params[idx + 1].toLowerCase();
    params.removeAt(idx);
    params.removeAt(idx);
  }

  String project = params.first;
  fcargs.add(project);

  Process process = await Process.start(
    'flutter',
    ['create', ...fcargs],
    runInShell: true,
    mode: ProcessStartMode.inheritStdio,
  );

  process.exitCode.then((_) {
    print('');
    print('Installing dependencies...');
    print('');

    _install(project, 'intl');
    _install(project, 'http');
    _install(project, 'uuid');

    switch (template) {
      case 'bloc':
        _install(project, 'equatable');
        _install(project, 'rxdart');
        _install(project, 'bloc');
        _install(project, 'flutter_bloc');
        break;
      case 'cubit':
        _install(project, 'equatable');
        _install(project, 'bloc');
        _install(project, 'flutter_bloc');
        break;
      case 'get':
      case 'getx':
        _install(project, 'equatable');
        _install(project, 'get');
        break;
      case 'mobx':
        _install(project, 'mobx');
        _install(project, 'mobx_codegen');
        _install(project, 'flutter_mobx');
        break;
      case 'riverpod':
        _install(project, 'equatable');
        _install(project, 'flutter_riverpod');
        break;
      case 'provider':
      default:
        _install(project, 'provider');
        break;
    }

    _templateAll(project);

    switch (template) {
      case 'bloc':
        _templateBloc(project);
        break;
      case 'cubit':
        _templateCubit(project);
        break;
      case 'get':
      case 'getx':
        _templateGetx(project);
        break;
      case 'mobx':
        _templateMobx(project);
        break;
      case 'riverpod':
        _templateRiverpod(project);
        break;
      case 'provider':
      default:
        _templateProvider(project);
        break;
    }

    exit(0);
  });
}