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