This commit is contained in:
bluesea 2024-05-15 16:43:57 +08:00
parent f4d9147bcd
commit a471816160
4 changed files with 33 additions and 14 deletions

View File

@ -40,6 +40,15 @@ class DownloadPageController extends GetxController {
await DownloadManager.setWallpaperNative(imgUrl); 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();
}
} }

View File

@ -30,12 +30,12 @@ class DownloadPageView extends GetView<DownloadPageController> {
padding: const EdgeInsets.symmetric(horizontal: 5), padding: const EdgeInsets.symmetric(horizontal: 5),
// padding: const EdgeInsets.fromLTRB(5, 50, 5, 0), // padding: const EdgeInsets.fromLTRB(5, 50, 5, 0),
children: List.generate(controller.dataItems.length, (index) { 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'; var imgUrl = '${controller.localDir.value}/$fileName';
return Stack(// return Stack(//
children: [ children: [
@ -45,15 +45,6 @@ class DownloadPageView extends GetView<DownloadPageController> {
height: double.infinity, height: double.infinity,
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
// Image.file(imgUrl),
// FadeInImage.loadImageByFile(
// width: double.infinity,
// height: double.infinity,
// placeholder: kTransparentImage,
// image: imgUrl,
// fit: BoxFit.cover,
// ),
Material( Material(
color: Colors.transparent, color: Colors.transparent,
child: InkWell( child: InkWell(
@ -72,7 +63,7 @@ class DownloadPageView extends GetView<DownloadPageController> {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
// column来说就是水平方向的布局方式 // column来说就是水平方向的布局方式
crossAxisAlignment: CrossAxisAlignment.center, 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 = [ List<Widget> wg = [
IconButton(onPressed:() { IconButton(onPressed:() {
controller.saveImgToAlbum(imgUrl); controller.saveImgToAlbum(imgUrl);
@ -97,6 +88,10 @@ class DownloadPageView extends GetView<DownloadPageController> {
}, icon: const Icon(Icons.wallpaper),color: Colors.white,)); }, 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; return wg;
} }
} }

View File

@ -35,8 +35,13 @@ class DBManager {
static List<LocalImageInfo> allImgs() { static List<LocalImageInfo> allImgs() {
var lis = DBManager.box.values.toList(); var lis = DBManager.box.values.toList();
return lis ; return lis ;
} }
static void deleteImg(LocalImageInfo item ) {
DBManager.box.delete(item.key);
}
} }

View File

@ -114,7 +114,17 @@ class DownloadManager {
return result; 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');
}
}