generateScreen function

Future<void> generateScreen({
  1. String? fallbackDartSdkPath,
  2. required String outputDirPath,
  3. required String screenName,
  4. required String controllerTemplateFilePath,
  5. required String screenTemplateFilePath,
  6. required String viewTemplateFilePath,
  7. required String bindingsTemplateFilePath,
  8. String path = '',
  9. bool isAccessibleOnlyIfLoggedIn = false,
  10. bool isAccessibleOnlyIfLoggedInAndVerified = false,
  11. bool isAccessibleOnlyIfLoggedOut = false,
  12. bool isRedirectable = false,
  13. Map<String, String> internalParameters = const {},
  14. Set<String> queryParameters = const {},
  15. String makeup = '',
  16. String title = '',
  17. Set<String> partFileDirs = const {},
})

Implementation

Future<void> generateScreen({
  String? fallbackDartSdkPath,
  required String outputDirPath,
  required String screenName,
  required String controllerTemplateFilePath,
  required String screenTemplateFilePath,
  required String viewTemplateFilePath,
  required String bindingsTemplateFilePath,
  String path = '',
  bool isAccessibleOnlyIfLoggedIn = false,
  bool isAccessibleOnlyIfLoggedInAndVerified = false,
  bool isAccessibleOnlyIfLoggedOut = false,
  bool isRedirectable = false,
  Map<String, String> internalParameters = const {},
  Set<String> queryParameters = const {},
  String makeup = '',
  String title = '',
  Set<String> partFileDirs = const {},
}) async {
  Here().debugLogStart('Starting generator. Please wait...');
  final screenClassKey = screenName.toSnakeCase();
  final screenClassName = screenName.toPascalCase();
  const BINDINGS_FILE_NAME = '_bindings.g.dart';
  const CONTROLLER_FILE_NAME = '_controller.dart';
  final screenFileName = '$screenClassKey.dart';
  const VIEW_FILE_NAME = '_view.dart';
  final i1 = internalParameters.entries
      .map(
        (e) => 'late final ${e.key} = this.configuration.${e.key};',
      )
      .join('\n');
  final q1 = queryParameters
      .map((e) => 'late final $e = this.configuration.$e;')
      .join('\n');
  final data = {
    '___SCREEN_CLASS___': screenClassName,
    '___BINDINGS_FILE___': BINDINGS_FILE_NAME,
    '___CONTROLLER_FILE___': CONTROLLER_FILE_NAME,
    '___SCREEN_FILE___': screenFileName,
    '___VIEW_FILE___': VIEW_FILE_NAME,
    '___Q1___': q1,
    '___I1___': i1,
  };
  final folderDirPath = p.joinAll(
    [
      outputDirPath,
      if (path.isNotEmpty)
        path.startsWith(RegExp(r'[\\/]')) ? path.substring(1) : path,
      screenClassKey,
    ],
  );
  final controllerFilePath = p.join(folderDirPath, CONTROLLER_FILE_NAME);
  await _writeFile(
    controllerTemplateFilePath,
    controllerFilePath,
    data,
  );
  final screenFilePath = p.join(folderDirPath, screenFileName);
  await _writeScreenFile(
    screenTemplateFilePath,
    screenFilePath,
    data,
    path: path,
    isAccessibleOnlyIfLoggedIn: isAccessibleOnlyIfLoggedIn,
    isAccessibleOnlyIfLoggedInAndVerified:
        isAccessibleOnlyIfLoggedInAndVerified,
    isAccessibleOnlyIfLoggedOut: isAccessibleOnlyIfLoggedOut,
    isRedirectable: isRedirectable,
    internalParameters: internalParameters,
    queryParameters: queryParameters,
    makeup: makeup,
    title: title,
    partFileDirs: partFileDirs,
  );
  final stateFilePath = p.join(folderDirPath, VIEW_FILE_NAME);
  await _writeFile(
    viewTemplateFilePath,
    stateFilePath,
    data,
  );
  await generateScreenBindings(
    fallbackDartSdkPath: fallbackDartSdkPath,
    rootDirPaths: {folderDirPath},
    templateFilePath: bindingsTemplateFilePath,
  );
  Here().debugLogStop('Done!');
}