replaceFilesText function

void replaceFilesText(
  1. File file,
  2. String replaceValue,
  3. String newValue
)

Implementation

void replaceFilesText(File file, String replaceValue, String newValue) async {
  if (!file.existsSync()) {
    return;
  }

  String fileContent = file.readAsStringSync();
  if (fileContent.contains(replaceValue)) {
    fileContent = fileContent.replaceAll(replaceValue, newValue);
    file = await file.writeAsString(fileContent);
  }
}