From f0c7bfd52e227de90f369b66c0eae67082ecefa7 Mon Sep 17 00:00:00 2001 From: deltamaya Date: Mon, 28 Oct 2024 17:20:53 +0800 Subject: [PATCH] fix selectFile() --- lib/utils/io.dart | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/utils/io.dart b/lib/utils/io.dart index f61206c..2babf42 100644 --- a/lib/utils/io.dart +++ b/lib/utils/io.dart @@ -160,11 +160,15 @@ class DirectoryPicker { Future selectFile({required List ext}) async { file_selector.XTypeGroup typeGroup = file_selector.XTypeGroup( label: 'files', - extensions: ext, + extensions: App.isMacOS || App.isIOS ? null : ext, ); final file_selector.XFile? file = await file_selector.openFile( acceptedTypeGroups: [typeGroup], ); + if (file == null) return null; + if (!ext.contains(file?.path.split(".").last)) { + return null; + } return file; } @@ -175,18 +179,18 @@ Future selectDirectory() async { Future saveFile( {Uint8List? data, required String filename, File? file}) async { - if(data == null && file == null) { + if (data == null && file == null) { throw Exception("data and file cannot be null at the same time"); } - if(data != null) { + if (data != null) { var cache = FilePath.join(App.cachePath, filename); - if(File(cache).existsSync()) { + if (File(cache).existsSync()) { File(cache).deleteSync(); } await File(cache).writeAsBytes(data); file = File(cache); } - if(App.isMobile) { + if (App.isMobile) { final params = SaveFileDialogParams(sourceFilePath: file!.path); await FlutterFileDialog.saveFile(params: params); } else {