saveFile method
Implementation
Future<String?> saveFile({
required List<int> bytes,
required String fileName,
String? dialogTitle,
String? initialDirectory,
List<String>? allowedExtensions,
}) async {
bool hasPermission = await _checkStoragePermission();
if (!hasPermission) return null;
try {
final path = await fp.FilePicker.platform.saveFile(
dialogTitle: dialogTitle ?? 'Save File',
fileName: fileName,
initialDirectory: initialDirectory,
type: allowedExtensions != null ? fp.FileType.custom : fp.FileType.any,
allowedExtensions: allowedExtensions,
);
if (path != null) {
final file = File(path);
await file.writeAsBytes(bytes);
return path;
}
} catch (e) {
print('Error saving file: $e');
}
return null;
}