updateFileContent static method

Future<void> updateFileContent({
  1. required String oldString,
  2. required String newString,
  3. required String filePath,
})

Updates the contents of the file at the given filePath by replacing all occurrences of oldString with newString.

Throws an exception if the file cannot be read or written to.

Implementation

static Future<void> updateFileContent({
  required String oldString,
  required String newString,
  required String filePath
}) async {
  final file = File(filePath);
  String content = await file.readAsString();
  content = content.replaceAll(oldString, newString);
  await file.writeAsString(content);
}