fdsa
This commit is contained in:
parent
39ea0327ba
commit
46293a379a
@ -2,7 +2,7 @@ PODS:
|
|||||||
- Flutter (1.0.0)
|
- Flutter (1.0.0)
|
||||||
- flutter_keyboard_visibility (0.0.1):
|
- flutter_keyboard_visibility (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
- image_gallery_saver (1.5.0):
|
- image_gallery_saver (2.0.2):
|
||||||
- Flutter
|
- Flutter
|
||||||
- path_provider_foundation (0.0.1):
|
- path_provider_foundation (0.0.1):
|
||||||
- Flutter
|
- Flutter
|
||||||
@ -32,7 +32,7 @@ EXTERNAL SOURCES:
|
|||||||
SPEC CHECKSUMS:
|
SPEC CHECKSUMS:
|
||||||
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
|
||||||
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
|
flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069
|
||||||
image_gallery_saver: 259eab68fb271cfd57d599904f7acdc7832e7ef2
|
image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb
|
||||||
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
|
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
|
||||||
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
|
permission_handler_apple: e76247795d700c14ea09e3a2d8855d41ee80a2e6
|
||||||
|
|
||||||
|
|||||||
@ -27,5 +27,10 @@ class ImgCategoryPageController extends GetxController {
|
|||||||
|
|
||||||
Future < void> saveImgToAlbum(String imgUrl) async {
|
Future < void> saveImgToAlbum(String imgUrl) async {
|
||||||
await DownloadManager.saveNetworkImage(imgUrl);
|
await DownloadManager.saveNetworkImage(imgUrl);
|
||||||
|
|
||||||
|
//如果是android,还应该调用设置壁纸的功能
|
||||||
|
//....
|
||||||
|
//给结果提示框
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,7 +9,7 @@ class ImgScanPageController extends GetxController {
|
|||||||
RxInt currentIndex = RxInt(0);
|
RxInt currentIndex = RxInt(0);
|
||||||
RxInt showAppbar = RxInt(0);//控制appbar显示....
|
RxInt showAppbar = RxInt(0);//控制appbar显示....
|
||||||
Timer? _timer;
|
Timer? _timer;
|
||||||
|
var albumPermisonisDenied = false.obs;
|
||||||
@override
|
@override
|
||||||
void onInit(){
|
void onInit(){
|
||||||
super.onInit();
|
super.onInit();
|
||||||
@ -33,11 +33,21 @@ class ImgScanPageController extends GetxController {
|
|||||||
|
|
||||||
Future < void> downloadImg() async {
|
Future < void> downloadImg() async {
|
||||||
String urlStr = dataModel.data![currentIndex.value].original!;
|
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(){
|
void showAppbarAction(){
|
||||||
showAppbar.value = 1;
|
showAppbar.value = 1;
|
||||||
cancelTimer();
|
cancelTimer();
|
||||||
|
|||||||
@ -85,6 +85,7 @@ class ImgScanPageView extends GetView<ImgScanPageController> {
|
|||||||
),
|
),
|
||||||
IconButton(onPressed:() {
|
IconButton(onPressed:() {
|
||||||
print("设置壁纸");
|
print("设置壁纸");
|
||||||
|
controller.saveImgToAlbum();
|
||||||
|
|
||||||
}, icon: const Icon(Icons.wallpaper),color: Colors.white,),
|
}, icon: const Icon(Icons.wallpaper),color: Colors.white,),
|
||||||
const Spacer(
|
const Spacer(
|
||||||
|
|||||||
@ -3,9 +3,19 @@ import 'dart:io';
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
||||||
import 'package:wallpaper/utils/local_img_manager.dart';
|
import 'package:wallpaper/utils/local_img_manager.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
|
||||||
class DownloadManager {
|
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();
|
var httpClient = HttpClient();
|
||||||
try {
|
try {
|
||||||
// option: Options(responseType: ResponseType.bytes)
|
// option: Options(responseType: ResponseType.bytes)
|
||||||
@ -16,9 +26,14 @@ class DownloadManager {
|
|||||||
// print(fileName);
|
// print(fileName);
|
||||||
//写入数据库信息
|
//写入数据库信息
|
||||||
//.....
|
//.....
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
print("the error:${error}");
|
print("the error:${error}");
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import 'package:crypto/crypto.dart';
|
|||||||
|
|
||||||
class LocalImgManager {
|
class LocalImgManager {
|
||||||
static Future<String> getImgLocalDir() async {
|
static Future<String> getImgLocalDir() async {
|
||||||
Directory dir = await getTemporaryDirectory();
|
Directory dir = await getApplicationCacheDirectory();
|
||||||
return dir.path;
|
return dir.path;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ class LocalImgManager {
|
|||||||
String fileName = "img_${LocalImgManager.sha1RandomString()}.jpg";
|
String fileName = "img_${LocalImgManager.sha1RandomString()}.jpg";
|
||||||
var localDir = await getImgLocalDir();
|
var localDir = await getImgLocalDir();
|
||||||
var filePath = '$localDir/$fileName';
|
var filePath = '$localDir/$fileName';
|
||||||
// print("the filepath:$filePath ");
|
print("the filepath:$filePath ");
|
||||||
File imageFile=File(filePath);
|
File imageFile=File(filePath);
|
||||||
if(imageFile.existsSync()){
|
if(imageFile.existsSync()){
|
||||||
print("图片已存在");
|
print("图片已存在");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user