Explorar el Código

[fit]修改权限跳转,修改无图片时展示逻辑

云天逵 hace 9 meses
padre
commit
2572050936
Se han modificado 2 ficheros con 126 adiciones y 115 borrados
  1. 13 12
      lib/module/home/home_controller.dart
  2. 113 103
      lib/module/home/home_view.dart

+ 13 - 12
lib/module/home/home_controller.dart

@@ -84,7 +84,8 @@ class HomeController extends BaseController {
 
   List<PieData> get pieDataList => [
         PieData("PhotoSpace", photoSpacePercentage, Colors.blue),
-        PieData("OtherUsed", usedSpacePercentage - photoSpacePercentage, Colors.red),
+        PieData("OtherUsed", usedSpacePercentage - photoSpacePercentage,
+            Colors.red),
         PieData("totalSpace", totalSpace.value, Colors.grey.withOpacity(0.1)),
       ];
 
@@ -101,9 +102,13 @@ class HomeController extends BaseController {
         totalSpace.value = 200.0;
         usedSpace.value = 50.0;
         photoSpace.value = 30.0;
-        freeSpace.value = 0.0;
+        freeSpace.value = 150.0;
+        isScreenShotScanned.value = true;
+        isBlurryScanned.value = true;
+        isPeopleScanned.value = true;
+        isSimilarScanned.value = true;
+        isStorageScanned.value = true;
       });
-
     }
 
     // if (await Permission.photos.request().isGranted) {
@@ -141,8 +146,8 @@ class HomeController extends BaseController {
     if (Platform.isAndroid) {
       loadPhotosFromDirectory();
     }
-
-    if (await Permission.photos.request().isGranted) {
+   var result= await Permission.photos.request();
+    if (result.isGranted) {
       PhotoManager.clearFileCache();
       getStorageInfo();
 
@@ -151,8 +156,10 @@ class HomeController extends BaseController {
       await handleBlurryPhotos();
       await handlePeoplePhotos();
       await handleSimilarPhotos();
+    } else if (result.isPermanentlyDenied) {
+      ToastUtil.show("Please enable the album permission");
+      openAppSettings();
     } else {
-
       ToastUtil.show("Please enable the album permission");
     }
   }
@@ -211,7 +218,6 @@ class HomeController extends BaseController {
           var asset = ImagePickerUtil.blurryPhotos.first;
           blurryPhoto.value = asset;
         }
-
       } catch (e) {
         print('Error loading photos: $e');
       }
@@ -259,7 +265,6 @@ class HomeController extends BaseController {
   }
 
   Future<void> handleScreenPhotos() async {
-
     final photoClassify = ClassifyPhoto();
     try {
       print('开始获取截图照片');
@@ -280,7 +285,6 @@ class HomeController extends BaseController {
   }
 
   Future<void> handleBlurryPhotos() async {
-
     final photoClassify = ClassifyPhoto();
     try {
       print('开始获取模糊照片');
@@ -301,7 +305,6 @@ class HomeController extends BaseController {
   }
 
   Future<void> handlePeoplePhotos() async {
-
     final photoClassify = ClassifyPhoto();
     try {
       print('开始获取人物照片');
@@ -329,7 +332,6 @@ class HomeController extends BaseController {
   }
 
   Future<void> handleSimilarPhotos() async {
-
     final photoClassify = ClassifyPhoto();
     try {
       print('开始获取相似照片');
@@ -350,7 +352,6 @@ class HomeController extends BaseController {
             }
           }
         }
-
       }
     } catch (e, stackTrace) {
       print('获取照片失败: $e');

+ 113 - 103
lib/module/home/home_view.dart

@@ -32,17 +32,17 @@ class HomePage extends BaseView<HomeController> {
         SafeArea(
           child: SingleChildScrollView(
               child: Column(
-            children: [
-              titleCard(),
-              storageCard(),
-              similarCard(),
-              quickPhotoCard(),
-              peopleCard(),
-              // locationsCard(),
-              screenshotsAndBlurryCard(),
-              SizedBox(height: 40.h),
-            ],
-          )),
+                children: [
+                  titleCard(),
+                  storageCard(),
+                  similarCard(),
+                  quickPhotoCard(),
+                  peopleCard(),
+                  // locationsCard(),
+                  screenshotsAndBlurryCard(),
+                  SizedBox(height: 40.h),
+                ],
+              )),
         ),
         IgnorePointer(
           child: Assets.images.bgHome.image(
@@ -187,7 +187,7 @@ class HomePage extends BaseView<HomeController> {
                           controller.totalSpace.value),
                       style: TextStyle(
                         color:
-                            Colors.white.withValues(alpha: 0.6000000238418579),
+                        Colors.white.withValues(alpha: 0.6000000238418579),
                         fontSize: 13.sp,
                         fontWeight: FontWeight.w400,
                       ),
@@ -196,7 +196,7 @@ class HomePage extends BaseView<HomeController> {
                       text: 'GB',
                       style: TextStyle(
                         color:
-                            Colors.white.withValues(alpha: 0.6000000238418579),
+                        Colors.white.withValues(alpha: 0.6000000238418579),
                         fontSize: 13.sp,
                         fontWeight: FontWeight.w500,
                       ),
@@ -379,11 +379,26 @@ class HomePage extends BaseView<HomeController> {
                 return Row(
                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
                   children: List.generate(4, (index) {
+                    if (!controller.isSimilarScanned.value) {
+                      return ImageContainer(
+                        size: 70.w,
+                        image: Opacity(
+                          opacity: 0.22,
+                          child: Lottie.asset(
+                            Assets.anim.animLoadingPhoto,
+                            repeat: true,
+                            width: 100.w,
+                            height: 100.w,
+                          ),
+                        ),
+                      );
+                    }
                     var image = Assets.images.iconHomeNoPhoto.image(
                       width: 70.w * 0.45,
                       height: 70.w * 0.45,
                     );
-                    if (controller.similarPhotos.length > index) {
+                    if (controller.isSimilarScanned.value &&
+                        controller.similarPhotos.length > index) {
                       image = AssetEntityImage(
                           width: 70.w,
                           height: 70.w,
@@ -398,29 +413,7 @@ class HomePage extends BaseView<HomeController> {
                             );
                           });
                     }
-                    return controller.similarPhotos.isNotEmpty
-                        ? image
-                        : ImageContainer(
-                      size: 70.w,
-                      image: Opacity(
-                        opacity: 0.22,
-                        child: Lottie.asset(Assets.anim.animNoPhoto,
-                            repeat: true, width: 100.w, height: 100.w),
-                      ),
-                      // AssetEntityImage(
-                      //         width: 70.w,
-                      //         height: 70.w,
-                      //         controller.similarPhotos[index],
-                      //         isOriginal: false,
-                      //         thumbnailSize: const ThumbnailSize.square(300),
-                      //         fit: BoxFit.cover,
-                      //         errorBuilder: (context, error, stackTrace) {
-                      //           return Assets.images.iconHomeNoPhoto.image(
-                      //             width: 70.w * 0.45,
-                      //             height: 70.w * 0.45,
-                      //           );
-                      //         },
-                    );
+                    return ImageContainer(size: 70.w, image: image);
                   }),
                 );
               }),
@@ -483,6 +476,16 @@ class HomePage extends BaseView<HomeController> {
                     return Row(
                       mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                       children: List.generate(2, (index) {
+                        if (!controller.isPeopleScanned.value) {
+                          return ImageContainer(
+                            size: 146.w,
+                            image: Opacity(
+                              opacity: 0.22,
+                              child: Lottie.asset(Assets.anim.animLoadingPhoto,
+                                  repeat: true, width: 100.w, height: 100.w),
+                            ),
+                          );
+                        }
                         var image = Assets.images.iconHomeNoPhoto.image(
                           width: 146.w * 0.45,
                           height: 146.w * 0.45,
@@ -496,20 +499,14 @@ class HomePage extends BaseView<HomeController> {
                               thumbnailSize: const ThumbnailSize.square(300),
                               fit: BoxFit.cover,
                               errorBuilder: (context, error, stackTrace) {
-                            return Assets.images.iconHomeNoPhoto.image(
-                              width: 146.w * 0.45,
-                              height: 146.w * 0.45,
-                            );
-                          });
+                                return Assets.images.iconHomeNoPhoto.image(
+                                  width: 146.w * 0.45,
+                                  height: 146.w * 0.45,
+                                );
+                              });
                         }
                         return ImageContainer(
-                          image: controller.peoplePhotos.length > index ? image : Opacity(
-                            opacity: 0.22,
-                            child: Lottie.asset(Assets.anim.animNoPhoto,
-                                repeat: true,
-                                width: 140.w,
-                                height: 140.w),
-                          ),
+                          image: image,
                           size: 146.w,
                           // Image.file(
                           //   width: 146.w,
@@ -588,27 +585,31 @@ class HomePage extends BaseView<HomeController> {
                       ),
                     ),
                     child: Obx(() {
+
                       return Center(
                         child: controller.locationPhoto.value == null
                             ? Opacity(
-                                opacity: 0.22,
-                                child: Lottie.asset(Assets.anim.animNoPhoto,
-                                    repeat: true, width: 160.w, height: 160.w),
-                              )
+                          opacity: 0.22,
+                          child: Lottie.asset(
+                              Assets.anim.animLoadingPhoto,
+                              repeat: true,
+                              width: 160.w,
+                              height: 160.w),
+                        )
                             : AssetEntityImage(
-                                width: 304.w,
-                                height: 171.h,
-                                controller.locationPhoto.value!,
-                                isOriginal: false,
-                                thumbnailSize: const ThumbnailSize.square(300),
-                                fit: BoxFit.cover,
-                                errorBuilder: (context, error, stackTrace) {
-                                  return Assets.images.iconHomeNoPhoto.image(
-                                    width: 60.w,
-                                    height: 60.h,
-                                  );
-                                },
-                              ),
+                          width: 304.w,
+                          height: 171.h,
+                          controller.locationPhoto.value!,
+                          isOriginal: false,
+                          thumbnailSize: const ThumbnailSize.square(300),
+                          fit: BoxFit.cover,
+                          errorBuilder: (context, error, stackTrace) {
+                            return Assets.images.iconHomeNoPhoto.image(
+                              width: 60.w,
+                              height: 60.h,
+                            );
+                          },
+                        ),
                         // Image.file(
                         //         width: 304.w,
                         //         height: 171.h,
@@ -655,26 +656,31 @@ class HomePage extends BaseView<HomeController> {
                   : 'Clean up',
               ImagePickerUtil.formatFileSize(
                   ImagePickerUtil.screenshotsSize.value),
-              controller.screenshotPhoto.value == null
+              !controller.isScreenShotScanned.value
                   ? Opacity(
-                      opacity: 0.22,
-                      child: Lottie.asset(Assets.anim.animNoPhoto,
-                          repeat: true, width: 100.w, height: 100.w),
-                    )
+                opacity: 0.22,
+                child: Lottie.asset(Assets.anim.animLoadingPhoto,
+                    repeat: true, width: 100.w, height: 100.w),
+              ):
+              controller.screenshotPhoto.value == null
+                  ? Assets.images.iconHomeNoPhoto.image(
+                width: 60.w,
+                height: 60.h,
+              )
                   : AssetEntityImage(
-                      width: 144.w,
-                      height: 142.h,
-                      controller.screenshotPhoto.value!,
-                      isOriginal: false,
-                      thumbnailSize: const ThumbnailSize.square(300),
-                      fit: BoxFit.cover,
-                      errorBuilder: (context, error, stackTrace) {
-                        return Assets.images.iconHomeNoPhoto.image(
-                          width: 60.w,
-                          height: 60.h,
-                        );
-                      },
-                    ),
+                width: 144.w,
+                height: 142.h,
+                controller.screenshotPhoto.value!,
+                isOriginal: false,
+                thumbnailSize: const ThumbnailSize.square(300),
+                fit: BoxFit.cover,
+                errorBuilder: (context, error, stackTrace) {
+                  return Assets.images.iconHomeNoPhoto.image(
+                    width: 60.w,
+                    height: 60.h,
+                  );
+                },
+              ),
               onTap: () {
                 controller.screenshotCleanClick();
               },
@@ -684,26 +690,30 @@ class HomePage extends BaseView<HomeController> {
                 !controller.isBlurryScanned.value ? 'Scanning...' : 'Clean up',
                 ImagePickerUtil.formatFileSize(
                     ImagePickerUtil.blurrySize.value),
-                controller.blurryPhoto.value == null
-                    ? Opacity(
-                        opacity: 0.22,
-                        child: Lottie.asset(Assets.anim.animNoPhoto,
-                            repeat: true, width: 100.w, height: 100.w),
-                      )
+                !controller.isBlurryScanned.value?
+                Opacity(
+                  opacity: 0.22,
+                  child: Lottie.asset(Assets.anim.animLoadingPhoto,
+                      repeat: true, width: 100.w, height: 100.w),
+                ): controller.blurryPhoto.value == null
+                    ? Assets.images.iconHomeNoPhoto.image(
+                  width: 60.w,
+                  height: 60.w,
+                )
                     : AssetEntityImage(
-                        width: 144.w,
-                        height: 142.h,
-                        controller.blurryPhoto.value!,
-                        isOriginal: false,
-                        thumbnailSize: const ThumbnailSize.square(300),
-                        fit: BoxFit.cover,
-                        errorBuilder: (context, error, stackTrace) {
-                          return Assets.images.iconHomeNoPhoto.image(
-                            width: 60.w,
-                            height: 60.h,
-                          );
-                        },
-                      ), onTap: () {
+                  width: 144.w,
+                  height: 142.h,
+                  controller.blurryPhoto.value!,
+                  isOriginal: false,
+                  thumbnailSize: const ThumbnailSize.square(300),
+                  fit: BoxFit.cover,
+                  errorBuilder: (context, error, stackTrace) {
+                    return Assets.images.iconHomeNoPhoto.image(
+                      width: 60.w,
+                      height: 60.h,
+                    );
+                  },
+                ), onTap: () {
               controller.blurryCleanClick();
             }),
           ],