replaceWithinFile method

Future<File?> replaceWithinFile(
  1. String path,
  2. Pattern from,
  3. String to
)

Replace contents of file

Implementation

Future<File?> replaceWithinFile(String path, Pattern from, String to) async {
  final file = File(p.join('lib', 'brick', path));
  final fileExists = await file.exists();
  if (!fileExists) return null;

  final contents = await file.readAsString();
  final replacedContents = contents.replaceAll(from, to);
  return await file.writeAsString(replacedContents);
}