createSlate static method

dynamic createSlate(
  1. List<NyTemplate> templates, {
  2. bool? hasForceFlag,
})

Creates a new Slate using templates.

Implementation

static createSlate(List<NyTemplate> templates, {bool? hasForceFlag}) async {
  String pubspecYaml = await MetroService.loadAsset('pubspec.yaml');
  for (var template in templates) {
    for (var pluginRequired in template.pluginsRequired) {
      if ((!pubspecYaml.contains(pluginRequired))) {
        MetroConsole.writeInRed(
            "Your project is missing the $pluginRequired package in your pubspec.yaml file.");
        MetroConsole.writeInGreen("Run 'flutter pub add $pluginRequired'");
        exit(1);
      }
    }
  }

  for (var template in templates) {
    String templateName = template.name;
    switch (template.saveTo) {
      case controllersFolder:
        {
          if (templateName.contains("_controller")) {
            templateName = templateName.replaceAll("_controller", "");
          }
          await makeController(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false));
          break;
        }
      case widgetsFolder:
        {
          await makeStatelessWidget(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false));
          break;
        }
      case pagesFolder:
        {
          bool isAuthPage = false;
          if (template.options.containsKey('is_auth_page')) {
            isAuthPage = template.options['is_auth_page'];
          }
          bool isInitialPage = false;
          if (template.options.containsKey('is_initial_page')) {
            isInitialPage = template.options['is_initial_page'];
          }
          if (templateName.contains("_page")) {
            templateName = templateName.replaceAll("_page", "");
          }
          await makePage(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false),
              addToRoute: true,
              isAuthPage: isAuthPage,
              isInitialPage: isInitialPage);
          break;
        }
      case modelsFolder:
        {
          await makeModel(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false), addToConfig: true);
          break;
        }
      case themesFolder:
        {
          if (templateName.contains("_theme")) {
            templateName = templateName.replaceAll("_theme", "");
          }
          await makeTheme(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false));
          break;
        }
      case providerFolder:
        {
          if (templateName.contains("_provider")) {
            templateName = templateName.replaceAll("_provider", "");
          }
          await makeProvider(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false), addToConfig: true);
          break;
        }
      case eventsFolder:
        {
          if (templateName.contains("_event")) {
            templateName = templateName.replaceAll("_event", "");
          }
          await makeEvent(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false), addToConfig: true);
          break;
        }
      case networkingFolder:
        {
          if (templateName.contains("_api_service")) {
            templateName = templateName.replaceAll("_api_service", "");
          }
          await makeApiService(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false), addToConfig: true);
          break;
        }
      case themeColorsFolder:
        {
          if (templateName.contains("_theme_colors")) {
            templateName = templateName.replaceAll("_theme_colors", "");
          }
          await makeThemeColors(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false));
          break;
        }
      case formsFolder:
        {
          if (templateName.contains("_form")) {
            templateName = templateName.replaceAll("_form", "");
          }
          await makeForm(templateName, template.stub,
              forceCreate: (hasForceFlag ?? false));
          break;
        }
      default:
        {
          continue;
        }
    }
  }
}