diff --git a/lib/utils/download.dart b/lib/utils/download.dart index 42e7b7307..7ffe6cc9c 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(