updateTextThemeStyles static method

Future<void> updateTextThemeStyles({
  1. required List<String> textStyles,
  2. bool verbose = false,
})

Implementation

static Future<void> updateTextThemeStyles(
    {required List<String> textStyles, bool verbose = false}) async {
  if (verbose) {
    print(grey('\tUpdating AppTheme for TextStyles'));
  }

  final appTheme =
      File(join(Directory.current.path, FileConstants.appThemeFile));

  if (!await appTheme.exists()) {
    throw Exception("AppTheme file does not exist: ${appTheme.path}");
  }

  final content = appTheme.readAsStringSync();

  final newContent = content.replaceAllMapped(
      RegExp(r'AppTextThemeExtension\(\n(.*?\n)*?\s*\);'),
      (match) => 'AppTextThemeExtension(\n${textStyles.map(
            (e) => '\t\t$e: TextStyleConst.$e,\n',
          ).join()}\t);');

  appTheme.writeAsString(newContent);
}