diff --git a/lib/utils/image_utils.dart b/lib/utils/image_utils.dart index b3f724dd6..cd9ba0896 100644 --- a/lib/utils/image_utils.dart +++ b/lib/utils/image_utils.dart @@ -189,23 +189,11 @@ abstract class ImageUtils { if (file == null) { final String filePath = '$tmpDirPath/$name'; - final response = await Request().downloadFile( url.http2https, filePath, cancelToken: cancelToken, ); - - if (Platform.isAndroid) { - if (response.statusCode == 200) { - await SaverGallery.saveFile( - filePath: filePath, - fileName: name, - androidRelativePath: "Pictures/${Constants.appName}", - skipIfExists: false, - ).whenComplete(File(filePath).tryDel); - } - } return ( filePath: filePath, name: name, @@ -213,20 +201,30 @@ abstract class ImageUtils { del: true, ); } else { - if (Platform.isAndroid) { - await SaverGallery.saveFile( - filePath: file.path, - fileName: name, - androidRelativePath: "Pictures/${Constants.appName}", - skipIfExists: false, - ); - } - return (filePath: file.path, name: name, statusCode: 200, del: false); } }); final result = await Future.wait(futures, eagerError: true); - if (!Platform.isAndroid) { + if (Platform.isAndroid) { + final delList = []; + final saveList = []; + for (var i in result) { + if (i.del) delList.add(i.filePath); + if (i.statusCode == 200) { + saveList.add( + SaveFileData( + filePath: i.filePath, + fileName: i.name, + androidRelativePath: 'Pictures/${Constants.appName}', + ), + ); + } + } + await SaverGallery.saveFiles(saveList, skipIfExists: false); + for (var i in delList) { + File(i).tryDel(); + } + } else { for (var res in result) { if (res.statusCode == 200) { await saveFileImg( diff --git a/pubspec.lock b/pubspec.lock index 4e8563f3f..dd8abb027 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -174,10 +174,10 @@ packages: dependency: "direct dev" description: name: build_runner - sha256: "04f69b1502f66e22ae7990bbd01eb552b7f12793c4d3ea6e715d0ac5e98bcdac" + sha256: "7b5b569f3df370590a85029148d6fc66c7d0201fc6f1847c07dd85d365ae9fcd" url: "https://pub.dev" source: hosted - version: "2.10.2" + version: "2.10.3" built_collection: dependency: transitive description: @@ -1448,10 +1448,10 @@ packages: dependency: "direct main" description: name: saver_gallery - sha256: bf59475e50b73d666630bed7a5fdb621fed92d637f64e3c61ce81653ec6a833c + sha256: "1d942bd7f4fedc162d9a751e156ebac592e4b81fc2e757af82de9077f3437003" url: "https://pub.dev" source: hosted - version: "4.0.1" + version: "4.1.0" screen_brightness_android: dependency: "direct overridden" description: diff --git a/pubspec.yaml b/pubspec.yaml index 56d9853d2..3c58675be 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -55,7 +55,7 @@ dependencies: # 图片 cached_network_image: ^3.4.1 # extended_image: ^9.0.7 - saver_gallery: ^4.0.1 + saver_gallery: ^4.1.0 # QRCode # qr_flutter: ^4.1.0 @@ -291,7 +291,7 @@ dev_dependencies: flutter_lints: ^6.0.0 flutter_launcher_icons: ^0.14.4 # hive_generator: ^2.0.1 - build_runner: ^2.9.0 + build_runner: ^2.10.3 flutter_native_splash: ^2.4.6 flutter_launcher_icons: