From 629b82292ce800d4e5ca12ae7d7c6731df5034b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8D=8E=E8=BD=A9?= <646903573@qq.com> Date: Mon, 21 Dec 2020 18:04:00 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=8D=A2=E4=BF=9D=E5=AD=98=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E5=88=B0=E7=9B=B8=E5=86=8C=E7=9A=84=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/util/download/download.dart | 23 ++++++++++++++--------- pubspec.yaml | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/util/download/download.dart b/lib/util/download/download.dart index 5c44221..b8f8818 100644 --- a/lib/util/download/download.dart +++ b/lib/util/download/download.dart @@ -1,20 +1,22 @@ + import 'dart:collection'; +import 'dart:io'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; -import 'package:image_gallery_saver/image_gallery_saver.dart'; import 'package:path_provider/path_provider.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:save_image/save_image.dart'; class Download { static HashMap hashMap = HashMap(); Future fileToGallery( - String url, { - String postfix, - Function(int, int) progress, - }) async { + String url, { + String postfix, + Function(int, int) progress, + }) async { // 检查是否已有读写内存的权限 bool status = await Permission.storage.isGranted; @@ -33,14 +35,17 @@ class Download { var appDocDir = await getTemporaryDirectory(); String savePath = appDocDir.path + "/" + DateTime.now().toIso8601String().toString() + (strs[strs.length - 1].length > 4 ? (postfix ?? "") : strs[strs.length - 1]); await Dio().download(url, savePath, onReceiveProgress: (count, toal) { - if(progress!=null){ + if (progress != null) { progress(count, toal); } }); print(savePath); - final result = await ImageGallerySaver.saveFile(savePath); - print(result); - return "保存成功"; + var result = await SaveImage.save(imageBytes: File(savePath).readAsBytesSync()); + if (result != null && result) { + return "保存成功"; + } else { + return "保存失败"; + } } catch (e) { return "下载失败,原因:" + e.toString(); } finally { diff --git a/pubspec.yaml b/pubspec.yaml index 8dff1d7..39d8f8d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,7 +72,7 @@ dependencies: path_provider: ^1.4.0 #保存文件到相册 - image_gallery_saver: ^1.5.0 + save_image: ^1.0.1