mirror of
https://github.com/wgh136/pixes.git
synced 2025-09-27 12:57:24 +00:00
add actions
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'package:flutter_file_dialog/flutter_file_dialog.dart';
|
||||
import 'package:pixes/foundation/app.dart';
|
||||
|
||||
extension FSExt on FileSystemEntity {
|
||||
Future<void> deleteIfExists() async {
|
||||
@@ -43,4 +48,24 @@ String bytesToText(int bytes) {
|
||||
} else {
|
||||
return "${(bytes / 1024 / 1024 / 1024).toStringAsFixed(2)} GB";
|
||||
}
|
||||
}
|
||||
|
||||
void saveFile(File file) async{
|
||||
if(App.isDesktop) {
|
||||
var fileName = file.path.split('/').last;
|
||||
final FileSaveLocation? result =
|
||||
await getSaveLocation(suggestedName: fileName);
|
||||
if (result == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Uint8List fileData = await file.readAsBytes();
|
||||
String mimeType = 'image/${fileName.split('.').last}';
|
||||
final XFile textFile = XFile.fromData(
|
||||
fileData, mimeType: mimeType, name: fileName);
|
||||
await textFile.saveTo(result.path);
|
||||
} else {
|
||||
final params = SaveFileDialogParams(sourceFilePath: file.path);
|
||||
await FlutterFileDialog.saveFile(params: params);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user