ll
This commit is contained in:
parent
2e0e6acc26
commit
e9a3a4eec5
@ -39,7 +39,7 @@ class ImgCategoryPageController extends GetxController {
|
||||
//....
|
||||
}
|
||||
|
||||
void setWallpaper(String imgUrl) {
|
||||
print("....set wall....");
|
||||
Future <void> setWallpaper(String imgUrl) async {
|
||||
await DownloadManager.setWallpaper(imgUrl);
|
||||
}
|
||||
}
|
||||
@ -97,24 +97,20 @@ class ImgCategoryPageView extends GetView<ImgCategoryPageController> {
|
||||
List<Widget> getButtomWidge(String imgUrl){
|
||||
List<Widget> wg = [
|
||||
IconButton(onPressed:() {
|
||||
print("download....");
|
||||
|
||||
controller.downloadImg(imgUrl);
|
||||
|
||||
}, icon: Icon(Icons.download),color: Colors.white,),
|
||||
}, icon: const Icon(Icons.download),color: Colors.white,),
|
||||
|
||||
IconButton(onPressed:() {
|
||||
print("保存至相册");
|
||||
controller.saveImgToAlbum(imgUrl);
|
||||
|
||||
}, icon: Icon(Icons.album),color: Colors.white,),
|
||||
}, icon: const Icon(Icons.album),color: Colors.white,),
|
||||
];
|
||||
if (controller.isAndroid) {
|
||||
wg.add(IconButton(onPressed:() {
|
||||
print("设置壁纸");
|
||||
controller.setWallpaper(imgUrl);
|
||||
|
||||
}, icon: Icon(Icons.wallpaper),color: Colors.white,));
|
||||
}, icon: const Icon(Icons.wallpaper),color: Colors.white,));
|
||||
}
|
||||
return wg;
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.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';
|
||||
@ -61,15 +62,28 @@ class DownloadManager {
|
||||
var reqiest = await httpClient.getUrl(Uri.parse(urlStr));
|
||||
var response = await reqiest.close();
|
||||
var bytes = await consolidateHttpClientResponseBytes(response);
|
||||
|
||||
final result = await ImageGallerySaver.saveImage(
|
||||
// final result =
|
||||
await ImageGallerySaver.saveImage(
|
||||
Uint8List.fromList(bytes),
|
||||
quality: 60,
|
||||
name: "hello");
|
||||
print(result);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//android设置壁纸
|
||||
static Future<bool> setWallpaper(String urlStr) async {
|
||||
bool result;
|
||||
try {
|
||||
result = await AsyncWallpaper.setWallpaper(
|
||||
url: urlStr,
|
||||
wallpaperLocation: AsyncWallpaper.HOME_SCREEN,
|
||||
goToHome: false,
|
||||
// toastDetails: ToastDetails.success(),
|
||||
// errorToastDetails: ToastDetails.error(),
|
||||
);
|
||||
} on PlatformException {
|
||||
result = false;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user