This commit is contained in:
bluesea 2024-05-15 10:59:22 +08:00
parent 39ea0327ba
commit 46293a379a
6 changed files with 38 additions and 7 deletions

View File

@ -2,7 +2,7 @@ PODS:
- Flutter (1.0.0)
- flutter_keyboard_visibility (0.0.1):
- Flutter
- image_gallery_saver (1.5.0):
- image_gallery_saver (2.0.2):
- Flutter
- path_provider_foundation (0.0.1):
- Flutter
@ -32,7 +32,7 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
image_gallery_saver: 259eab68fb271cfd57d599904f7acdc7832e7ef2
image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6

View File

@ -27,5 +27,10 @@ class ImgCategoryPageController extends GetxController {
Future < void> saveImgToAlbum(String imgUrl) async {
await DownloadManager.saveNetworkImage(imgUrl);
//android,
//....
//
}
}

View File

@ -9,7 +9,7 @@ class ImgScanPageController extends GetxController {
RxInt currentIndex = RxInt(0);
RxInt showAppbar = RxInt(0);//appbar显示....
Timer? _timer;
var albumPermisonisDenied = false.obs;
@override
void onInit(){
super.onInit();
@ -33,11 +33,21 @@ class ImgScanPageController extends GetxController {
Future < void> downloadImg() async {
String urlStr = dataModel.data![currentIndex.value].original!;
await DownloadManager.downloadImgWithUrl(urlStr);
if ((await DownloadManager.downloadImgWithUrl(urlStr)) == false){
albumPermisonisDenied.value = true;
}
//
//....
}
Future < void> saveImgToAlbum() async {
String imgUrl = dataModel.data![currentIndex.value].original!;
await DownloadManager.saveNetworkImage(imgUrl);
//android,
//....
//
}
void showAppbarAction(){
showAppbar.value = 1;
cancelTimer();

View File

@ -85,6 +85,7 @@ class ImgScanPageView extends GetView<ImgScanPageController> {
),
IconButton(onPressed:() {
print("设置壁纸");
controller.saveImgToAlbum();
}, icon: const Icon(Icons.wallpaper),color: Colors.white,),
const Spacer(

View File

@ -3,9 +3,19 @@ import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:wallpaper/utils/local_img_manager.dart';
import 'package:permission_handler/permission_handler.dart';
class DownloadManager {
static Future<void> downloadImgWithUrl(String urlStr) async {
static Future<bool> downloadImgWithUrl(String urlStr) async {
//android先去判断存储权限的获取
// if (!await Permission.storage.request().isGranted) {
// return false;
// }
// await Permission.photos.request();
// Permission.photos.
var httpClient = HttpClient();
try {
// option: Options(responseType: ResponseType.bytes)
@ -16,9 +26,14 @@ class DownloadManager {
// print(fileName);
//
//.....
return true;
}
catch(error) {
print("the error:${error}");
return true;
}
}

View File

@ -11,7 +11,7 @@ import 'package:crypto/crypto.dart';
class LocalImgManager {
static Future<String> getImgLocalDir() async {
Directory dir = await getTemporaryDirectory();
Directory dir = await getApplicationCacheDirectory();
return dir.path;
}
@ -19,7 +19,7 @@ class LocalImgManager {
String fileName = "img_${LocalImgManager.sha1RandomString()}.jpg";
var localDir = await getImgLocalDir();
var filePath = '$localDir/$fileName';
// print("the filepath:$filePath ");
print("the filepath:$filePath ");
File imageFile=File(filePath);
if(imageFile.existsSync()){
print("图片已存在");