feat(update):添加图片长按下载
This commit is contained in:
@@ -11,45 +11,50 @@ import 'package:image_gallery_saver_plus/image_gallery_saver_plus.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class DownLoadImageTool {
|
||||
|
||||
// 请求照片库权限
|
||||
static Future<bool> requestPhotoPermission() async {
|
||||
// 检查当前权限状态
|
||||
// var status = await Permission.photos.status;
|
||||
var status = await Permission.storage.request();
|
||||
if (status.isDenied) {
|
||||
// 请求权限
|
||||
PermissionStatus status;
|
||||
if (Platform.isIOS) {
|
||||
status = await Permission.photosAddOnly.request();
|
||||
} else {
|
||||
status = await Permission.photos.request();
|
||||
|
||||
// 如果用户拒绝了权限,可以显示一个解释
|
||||
if (status.isPermanentlyDenied) {
|
||||
// 打开应用设置,让用户手动启用权限
|
||||
await openAppSettings();
|
||||
}
|
||||
}
|
||||
|
||||
return status.isGranted;
|
||||
if (status.isPermanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
|
||||
return status.isGranted || status.isLimited;
|
||||
}
|
||||
|
||||
// 或者请求存储权限(适用于Android)
|
||||
static Future<bool> requestStoragePermission() async {
|
||||
if (Platform.isIOS) {
|
||||
return requestPhotoPermission();
|
||||
}
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
// 对于Android 13及以上版本
|
||||
if (await DeviceInfoPlugin().androidInfo.then((info) => info.version.sdkInt) >= 33) {
|
||||
if (await DeviceInfoPlugin()
|
||||
.androidInfo
|
||||
.then((info) => info.version.sdkInt) >=
|
||||
33) {
|
||||
var status = await Permission.photos.request();
|
||||
if(status == PermissionStatus.denied){
|
||||
await requestPhotoPermission();
|
||||
if (status.isPermanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
return status.isGranted;
|
||||
return status.isGranted || status.isLimited;
|
||||
} else {
|
||||
// 对于Android 13以下版本
|
||||
var status = await Permission.storage.request();
|
||||
if (status.isPermanentlyDenied) {
|
||||
await openAppSettings();
|
||||
}
|
||||
return status.isGranted;
|
||||
}
|
||||
} else {
|
||||
// iOS使用照片权限
|
||||
return await requestPhotoPermission();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
///保存到相册
|
||||
@@ -98,10 +103,9 @@ class DownLoadImageTool {
|
||||
final result = await ImageGallerySaverPlus.saveImage(
|
||||
Uint8List.fromList(response.data),
|
||||
quality: 60,
|
||||
name: "hello",
|
||||
name: "flutter_common_${DateTime.now().millisecondsSinceEpoch}",
|
||||
isReturnImagePathOfIOS: true,
|
||||
);
|
||||
print('=result ============ $result');
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -127,7 +131,6 @@ class DownLoadImageTool {
|
||||
EasyLoading.dismiss();
|
||||
return null;
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
EasyLoading.dismiss();
|
||||
// debugPrint('Error fetching image: $e');
|
||||
|
||||
Reference in New Issue
Block a user