From e34fce6d0e93819d6a76c848c9d6693d01025fc8 Mon Sep 17 00:00:00 2001 From: bggRGjQaUbCoE Date: Sat, 28 Dec 2024 21:32:53 +0800 Subject: [PATCH] mod: save image: dissable dialog Signed-off-by: bggRGjQaUbCoE --- .../interactiveviewer_gallery.dart | 2 +- lib/utils/download.dart | 20 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart index 991de633..e1efd67a 100644 --- a/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart +++ b/lib/common/widgets/interactiveviewer_gallery/interactiveviewer_gallery.dart @@ -334,7 +334,7 @@ class _InteractiveviewerGalleryState extends State onTap: () { DownloadUtils.downloadImg( context, - widget.sources[currentIndex!], + widget.sources as List, ); }, child: const Text("保存全部图片"), diff --git a/lib/utils/download.dart b/lib/utils/download.dart index 26924aca..c1b4c218 100644 --- a/lib/utils/download.dart +++ b/lib/utils/download.dart @@ -93,10 +93,19 @@ class DownloadUtils { if (!await checkPermissionDependOnSdkInt(context)) { return; } + bool dispose = false; for (int i = 0; i < imgList.length; i++) { SmartDialog.showLoading( - msg: - '正在下载原图${imgList.length > 1 ? '${i + 1}/${imgList.length}' : ''}'); + msg: + '正在下载原图${imgList.length > 1 ? '${i + 1}/${imgList.length}' : ''}', + clickMaskDismiss: true, + onDismiss: () { + dispose = true; + if (i != imgList.length - 1) { + SmartDialog.showToast('已取消下载剩余图片'); + } + }, + ); var response = await Request().get( imgList[i], options: Options(responseType: ResponseType.bytes), @@ -117,9 +126,12 @@ class DownloadUtils { SmartDialog.dismiss(); } if (result.isSuccess) { - await SmartDialog.showToast('「$picName」已保存 '); + SmartDialog.showToast('「$picName」已保存 '); } else { - await SmartDialog.showToast('保存失败,${result.errorMessage}'); + SmartDialog.showToast('保存失败,${result.errorMessage}'); + } + if (dispose) { + break; } } } catch (err) {