safeWriteFileAsync function
Writes content to a file asynchronously, ensuring the parent directory exists.
Parameters:
Implementation
Future<void> safeWriteFileAsync(String targetPath, String content) async {
final file = File(targetPath);
try {
await file.parent.create(recursive: true);
await file.writeAsString(content, mode: FileMode.write, flush: true);
} catch (e) {
print('Error writing to file $targetPath: $e');
rethrow;
}
}