createFile method
Appends the given data to a file at the specified filePath.
If the file does not exist, it will be created.
Implementation
Future<void> createFile({
required String filePath,
required String data,
FileMode modeIfExist = FileMode.append,
}) async {
try {
final file = await File(filePath).create(recursive: true);
if (file.existsSync()) {
// Append to existing file
await file.writeAsString(data, mode: modeIfExist);
} else {
// Create a new file
await file.writeAsString(data);
}
} catch (e) {
logger.err(e.toString());
exit(ExitCode.osError.code);
}
}