createPostLocator method

void createPostLocator(
  1. String pathPage,
  2. String pageName,
  3. String apiName
)

Implementation

void createPostLocator(String pathPage, String pageName, String apiName) {
  String data = File(join(pathPage, 'locator.dart')).readAsStringSync();

  final bloc = find(
    '*',
    recursive: false,
    includeHidden: false,
    workingDirectory: join(pathPage, 'presentation', 'bloc'),
    types: [Find.directory],
  )
      .toList()
      .map((e) =>
          '${e.replaceAll('${join(pathPage, 'presentation', 'bloc')}$separator', '').camelCase}Bloc: locator()')
      .join(',');

  data = data.replaceAll(
    RegExp(r"\w*Cubit\((([\w,:\s]*(\(\))?)+)?\)"),
    '${pageName.pascalCase}Cubit($bloc,)',
  );

  data = data.replaceAll(RegExp(r';?(\s+)?}', multiLine: true), ''';}''');

  join(pathPage, 'locator.dart').write(data);

  StatusHelper.generated(join(pathPage, 'locator.dart'));
}