added file saver
This commit is contained in:
23
lib/utils/FileSaver.dart
Normal file
23
lib/utils/FileSaver.dart
Normal file
@@ -0,0 +1,23 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
// only tested on android!
|
||||
class FileSaver {
|
||||
static Future<String> getExternalDocumentPath() async {
|
||||
var permission = await Permission.storage.status;
|
||||
if(!permission.isGranted) {
|
||||
await Permission.storage.request();
|
||||
}
|
||||
var directory = Directory('/storage/emulated/0/Download');
|
||||
final externalPath = directory.path;
|
||||
await Directory(externalPath).create(recursive: true);
|
||||
return externalPath;
|
||||
}
|
||||
|
||||
static Future<File> writeBytes(List<int> bytes, String name) async {
|
||||
final path = await getExternalDocumentPath();
|
||||
var file = File('$path/$name');
|
||||
return file.writeAsBytes(bytes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user