writeFile function

Future<void> writeFile(
  1. String filePath,
  2. String content, {
  3. bool append = false,
})

Writes the given content to the file located at filePath. Set append to true to append the content to the file instead of overwriting it.

Implementation

Future<void> writeFile(
  String filePath,
  String content, {
  bool append = false,
}) async {
  final localSystemFilePath = toLocalSystemPathFormat(filePath);
  final file = File(localSystemFilePath);
  await file.parent.create(recursive: true);
  await file.writeAsString(
    content,
    mode: append ? FileMode.append : FileMode.write,
  );
}