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);
}
//
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.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;
}
}

View File

@ -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);
}
}

View File

@ -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');
}
}