From ce459701aad89f23cc7e11ff4cce8b8d913d7f37 Mon Sep 17 00:00:00 2001 From: orz12 Date: Mon, 22 Apr 2024 20:21:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=89=E5=8D=93=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=AD=98=E5=82=A8=E6=9D=83=E9=99=90=E8=B0=83=E6=95=B4=EF=BC=8C?= =?UTF-8?q?=E4=BB=85=E5=9C=A8Android13=E5=8F=8A=E4=BB=A5=E4=B8=8A=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E7=9B=B8=E5=86=8C=E6=8E=88=E6=9D=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/utils/download.dart | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/lib/utils/download.dart b/lib/utils/download.dart index 42e7b730..7ffe6cc9 100644 --- a/lib/utils/download.dart +++ b/lib/utils/download.dart @@ -1,10 +1,12 @@ import 'dart:typed_data'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:saver_gallery/saver_gallery.dart'; +import 'dart:io'; class DownloadUtils { // 获取存储权限 @@ -43,39 +45,52 @@ class DownloadUtils { PermissionStatus status = await Permission.photos.status; if (status == PermissionStatus.denied || status == PermissionStatus.permanentlyDenied) { - SmartDialog.show( - useSystem: true, - animationType: SmartAnimationType.centerFade_otherSlide, - builder: (BuildContext context) { - return AlertDialog( - title: const Text('提示'), - content: const Text('相册权限未授权'), - actions: [ - TextButton( - onPressed: () async { - openAppSettings(); - }, - child: const Text('去授权'), - ) - ], - ); - }, - ); + // SmartDialog.show( + // useSystem: true, + // animationType: SmartAnimationType.centerFade_otherSlide, + // builder: (BuildContext context) { + // return AlertDialog( + // title: const Text('提示'), + // content: const Text('相册权限未授权'), + // actions: [ + // TextButton( + // onPressed: () async { + // openAppSettings(); + // }, + // child: const Text('去授权'), + // ) + // ], + // ); + // }, + // ); return false; } else { return true; } } + static Future checkPermissionDependOnSdkInt() async { + if (Platform.isAndroid) { + final androidInfo = await DeviceInfoPlugin().androidInfo; + if (androidInfo.version.sdkInt <= 32) { + return await requestStoragePer(); + } else { + return await requestPhotoPer(); + } + } + return await requestStoragePer(); + } static Future downloadImg(String imgUrl, {String imgType = 'cover'}) async { try { - if (!await requestPhotoPer()) { - return false; + if (!await checkPermissionDependOnSdkInt()) { + // // return false; } - SmartDialog.showLoading(msg: '保存中'); + SmartDialog.showLoading(msg: '正在下载原图'); var response = await Dio() .get(imgUrl, options: Options(responseType: ResponseType.bytes)); + SmartDialog.dismiss(); + SmartDialog.showLoading(msg: '正在保存图片至图库'); String picName = "${imgType}_${DateTime.now().toString().replaceAll(' ', '_').replaceAll(':', '-').split('.').first}"; final SaveResult result = await SaverGallery.saveImage(