daf
This commit is contained in:
parent
f4d9147bcd
commit
a471816160
@ -40,6 +40,15 @@ class DownloadPageController extends GetxController {
|
||||
await DownloadManager.setWallpaperNative(imgUrl);
|
||||
}
|
||||
|
||||
//删除图片
|
||||
void deleteWallpaper(String imgUrl,int index) async{
|
||||
await DownloadManager.deleteWallpaperFile(imgUrl);
|
||||
DBManager.deleteImg(dataItems[index]);
|
||||
// ignore: invalid_use_of_protected_member
|
||||
dataItems.value.removeAt(index);
|
||||
|
||||
// dataItems.value = DBManager.allImgs();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -30,12 +30,12 @@ class DownloadPageView extends GetView<DownloadPageController> {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
// padding: const EdgeInsets.fromLTRB(5, 50, 5, 0),
|
||||
children: List.generate(controller.dataItems.length, (index) {
|
||||
return getBodyItem(controller.dataItems[index].localUrl!);
|
||||
return getBodyItem(controller.dataItems[index].localUrl!,index);
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
Stack getBodyItem(String fileName) {
|
||||
Stack getBodyItem(String fileName,int index) {
|
||||
var imgUrl = '${controller.localDir.value}/$fileName';
|
||||
return Stack(//堆叠效果
|
||||
children: [
|
||||
@ -45,15 +45,6 @@ class DownloadPageView extends GetView<DownloadPageController> {
|
||||
height: double.infinity,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
// Image.file(imgUrl),
|
||||
// FadeInImage.loadImageByFile(
|
||||
// width: double.infinity,
|
||||
// height: double.infinity,
|
||||
// placeholder: kTransparentImage,
|
||||
// image: imgUrl,
|
||||
// fit: BoxFit.cover,
|
||||
// ),
|
||||
|
||||
Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
@ -72,7 +63,7 @@ class DownloadPageView extends GetView<DownloadPageController> {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
// 交叉轴的布局方式,对于column来说就是水平方向的布局方式
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: getButtomWidge(imgUrl),
|
||||
children: getButtomWidge(imgUrl,index),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -84,7 +75,7 @@ class DownloadPageView extends GetView<DownloadPageController> {
|
||||
}
|
||||
|
||||
|
||||
List<Widget> getButtomWidge(String imgUrl){
|
||||
List<Widget> getButtomWidge(String imgUrl,int index){
|
||||
List<Widget> wg = [
|
||||
IconButton(onPressed:() {
|
||||
controller.saveImgToAlbum(imgUrl);
|
||||
@ -97,6 +88,10 @@ class DownloadPageView extends GetView<DownloadPageController> {
|
||||
|
||||
}, icon: const Icon(Icons.wallpaper),color: Colors.white,));
|
||||
}
|
||||
wg.add(IconButton(onPressed:() {
|
||||
controller.deleteWallpaper(imgUrl,index);
|
||||
|
||||
}, icon: const Icon(Icons.delete),color: Colors.red,));
|
||||
return wg;
|
||||
}
|
||||
}
|
||||
@ -35,8 +35,13 @@ class DBManager {
|
||||
|
||||
static List<LocalImageInfo> allImgs() {
|
||||
var lis = DBManager.box.values.toList();
|
||||
|
||||
return lis ;
|
||||
}
|
||||
|
||||
static void deleteImg(LocalImageInfo item ) {
|
||||
DBManager.box.delete(item.key);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -114,7 +114,17 @@ class DownloadManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//删除本地图片
|
||||
static Future<void> deleteWallpaperFile(String urlStr) async{
|
||||
// 删除文件
|
||||
final file = File(urlStr);
|
||||
if (await file.exists()) {
|
||||
await file.delete();
|
||||
print('文件已删除:$urlStr');
|
||||
} else {
|
||||
print('文件不存在:$urlStr');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user