feat: 图片保存到PiliPala目录(Android) issues #94
This commit is contained in:
@ -2,8 +2,8 @@ import 'dart:typed_data';
|
|||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:saver_gallery/saver_gallery.dart';
|
||||||
|
|
||||||
class DownloadUtils {
|
class DownloadUtils {
|
||||||
// 获取存储权限
|
// 获取存储权限
|
||||||
@ -15,25 +15,32 @@ class DownloadUtils {
|
|||||||
statuses[Permission.storage].toString();
|
statuses[Permission.storage].toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<bool> downloadImg(String imgUrl) async {
|
static Future<bool> downloadImg(String imgUrl,
|
||||||
await requestStoragePer();
|
{String imgType = 'cover'}) async {
|
||||||
SmartDialog.showLoading(msg: '保存中');
|
try {
|
||||||
var response = await Dio()
|
await requestStoragePer();
|
||||||
.get(imgUrl, options: Options(responseType: ResponseType.bytes));
|
SmartDialog.showLoading(msg: '保存中');
|
||||||
String picName =
|
var response = await Dio()
|
||||||
"plpl_cover_${DateTime.now().toString().split('-').join()}.png";
|
.get(imgUrl, options: Options(responseType: ResponseType.bytes));
|
||||||
final result = await ImageGallerySaver.saveImage(
|
String picName =
|
||||||
Uint8List.fromList(response.data),
|
"plpl_${imgType}_${DateTime.now().toString().split('-').join()}";
|
||||||
quality: 100,
|
final SaveResult result = await SaverGallery.saveImage(
|
||||||
name: picName,
|
Uint8List.fromList(response.data),
|
||||||
);
|
quality: 60,
|
||||||
SmartDialog.dismiss();
|
name: picName,
|
||||||
if (result != null) {
|
// 保存到 PiliPala文件夹
|
||||||
if (result['isSuccess']) {
|
androidRelativePath: "Pictures/PiliPala",
|
||||||
// ignore: avoid_print
|
androidExistNotSave: false,
|
||||||
|
);
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
if (result.isSuccess) {
|
||||||
await SmartDialog.showToast('「$picName」已保存 ');
|
await SmartDialog.showToast('「$picName」已保存 ');
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
|
} catch (err) {
|
||||||
|
SmartDialog.dismiss();
|
||||||
|
SmartDialog.showToast(err.toString());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
pubspec.lock
16
pubspec.lock
@ -653,14 +653,6 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "4.0.17"
|
version: "4.0.17"
|
||||||
image_gallery_saver:
|
|
||||||
dependency: "direct main"
|
|
||||||
description:
|
|
||||||
name: image_gallery_saver
|
|
||||||
sha256: "0aba74216a4d9b0561510cb968015d56b701ba1bd94aace26aacdd8ae5761816"
|
|
||||||
url: "https://pub.dev"
|
|
||||||
source: hosted
|
|
||||||
version: "2.0.3"
|
|
||||||
intl:
|
intl:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -1078,6 +1070,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.2"
|
version: "1.0.2"
|
||||||
|
saver_gallery:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: saver_gallery
|
||||||
|
sha256: "3131bba4257f69901437c0f1ebd692201ca5f34512d42667513a3802f1c171d1"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
screen_brightness:
|
screen_brightness:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -49,7 +49,7 @@ dependencies:
|
|||||||
# 图片
|
# 图片
|
||||||
cached_network_image: ^3.2.3
|
cached_network_image: ^3.2.3
|
||||||
extended_image: ^8.0.2
|
extended_image: ^8.0.2
|
||||||
image_gallery_saver: ^2.0.3
|
saver_gallery: ^2.0.1
|
||||||
|
|
||||||
# 存储
|
# 存储
|
||||||
path_provider: ^2.0.14
|
path_provider: ^2.0.14
|
||||||
|
Reference in New Issue
Block a user