saveTextFile static method

Future<void> saveTextFile(
  1. String folderPath,
  2. String fileName,
  3. String contents
)

Saves a text file with the given fileName (without extension) and contents to the specified folderPath. The file will have a .txt extension.

If the folder does not exist, it will be created recursively.

Implementation

static Future<void> saveTextFile(String folderPath, String fileName, String contents) async {
  final targetDir = Directory(folderPath);
  if (!await targetDir.exists()) {
    await targetDir.create(recursive: true);
  }
  String filePath = "${targetDir.path}/$fileName.txt";
  final file = File(filePath);

  await file.writeAsString(contents);
}