addToConfig static method

dynamic addToConfig({
  1. required String configName,
  2. required String classImport,
  3. required String createTemplate(
    1. String originalFile
    ),
})

Attempts to replace a file. Provide a configName to select which file to replace. Then you can use the callback originalFile to get the file and manipulate it.

Implementation

static addToConfig(
    {required String configName,
    required String classImport,
    required String Function(String originalFile) createTemplate}) async {
  // add it to the decoder config
  String filePath = "lib/config/$configName.dart";
  String originalFile = await loadAsset(filePath);

  if (originalFile.contains(classImport)) {
    return;
  }

  // create new file
  String fileCreated = createTemplate(originalFile);
  if (fileCreated == "") {
    return;
  }

  // Add import
  fileCreated = "$classImport\n$fileCreated";

  // save new file
  final File file = File(filePath);
  await file.writeAsString(fileCreated);
}