Browse Source

[fix]修改模糊程度blurRadius,计算大小加了个平台判断

云天逵 11 months ago
parent
commit
16cfb1a42c

+ 1 - 1
lib/base/base_photo_controller.dart

@@ -45,7 +45,7 @@ abstract class BasePhotoController extends BaseController {
       return;
     }
 
-    FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    FileSizeCalculatorUtil.calculateTotalSize(
         assetIds: selectedPhotosIds,
         updateValue: (double totalSize) {
           selectedFilesSize.value = totalSize; // 监听并更新 UI

+ 1 - 1
lib/module/calendar/calendar_month_controller.dart

@@ -110,7 +110,7 @@ class CalendarMonthController extends BaseController {
       return;
     }
 
-    FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    FileSizeCalculatorUtil.calculateTotalSize(
       assetIds: photoGroup.value.selectedPhotosIds,
       updateValue: (double totalSize) {
         photoGroup.value.selectedTotalSize.value = totalSize;

+ 1 - 1
lib/module/calendar/preview/calendar_preview_controller.dart

@@ -262,7 +262,7 @@ class CalendarPreviewController extends BaseController
       return;
     }
 
-    FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    FileSizeCalculatorUtil.calculateTotalSize(
       assetIds: photoGroup.value.selectedPhotosIds,
       updateValue: (double totalSize) {
         photoGroup.value.selectedTotalSize.value = totalSize;

+ 1 - 1
lib/module/calendar/selected_preview/calendar_selected_preview_controller.dart

@@ -138,7 +138,7 @@ class CalendarSelectedPreviewController extends BaseController {
       return;
     }
 
-    FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    FileSizeCalculatorUtil.calculateTotalSize(
       assetIds: photoGroup.value.selectedPhotosIds,
       updateValue: (double totalSize) {
         photoGroup.value.selectedTotalSize.value = totalSize;

+ 1 - 1
lib/module/people_photo/photo_group.dart

@@ -53,7 +53,7 @@ class PhotoGroup {
   }
 
   Future<void> initTotalSize() async {
-    await FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    await FileSizeCalculatorUtil.calculateTotalSize(
          assetIds: images.map((e) => e.id).toSet(), updateValue: (double totalSize) {
 
       this.totalSize.value = totalSize; // 监听并更新 UI

+ 8 - 8
lib/module/photo_info/photo_info_view.dart

@@ -88,7 +88,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                   shadows: [
                                     Shadow(
                                       color: Colors.black,
-                                      blurRadius: 2.r,
+                                      blurRadius: 5.r,
                                     ),
                                   ],
                                   color: Colors.white,
@@ -109,7 +109,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -133,7 +133,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -157,7 +157,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -181,7 +181,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -205,7 +205,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -229,7 +229,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,
@@ -253,7 +253,7 @@ class PhotoInfoPage extends BasePage<PhotoInfoController> {
                                         shadows: [
                                           Shadow(
                                             color: Colors.black,
-                                            blurRadius: 2.r,
+                                            blurRadius: 5.r,
                                           ),
                                         ],
                                         color: Colors.white,

+ 1 - 1
lib/module/photo_preview/photo_preview_controller.dart

@@ -195,7 +195,7 @@ class PhotoPreviewController extends BaseController
       selectedFilesSize.value = 0;
       return;
     }
-    FileSizeCalculatorUtil.calculateTotalSizeByIOS(
+    FileSizeCalculatorUtil.calculateTotalSize(
       assetIds: selectedPhotosIds,
       updateValue: (double totalSize) {
         selectedFilesSize.value = totalSize;

+ 46 - 17
lib/utils/file_size_calculator_util.dart

@@ -1,4 +1,5 @@
 import 'dart:ffi';
+import 'dart:io';
 
 import 'package:classify_photo/classify_photo.dart';
 import 'package:flutter/cupertino.dart';
@@ -17,11 +18,12 @@ class FileSizeCalculatorUtil {
       return;
     }
     double totalSize = 0;
-    totalSize = await ClassifyPhoto().calculatePhotosSize(assetIds.toList()) / 1024;
+    totalSize =
+        await ClassifyPhoto().calculatePhotosSize(assetIds.toList()) / 1024;
     updateValue(totalSize);
   }
 
-  static Future<void> calculateTotalSize({
+  static Future<void> calculateTotalSizeByAndroid({
     required Set<String> assetIds,
     required Function(double) updateValue,
   }) async {
@@ -62,6 +64,19 @@ class FileSizeCalculatorUtil {
     updateValue(totalSize);
   }
 
+  static Future<void> calculateTotalSize({
+    required Set<String> assetIds,
+    required Function(double) updateValue,
+  }) async {
+    if (Platform.isIOS) {
+      await calculateTotalSizeByIOS(
+          assetIds: assetIds, updateValue: updateValue);
+    } else {
+      await calculateTotalSizeByAndroid(
+          assetIds: assetIds, updateValue: updateValue);
+    }
+  }
+
   /// 获取文件大小
   static Future<double> getFileSize(String assetId) async {
     if (fileSizeCache.containsKey(assetId)) {
@@ -71,28 +86,42 @@ class FileSizeCalculatorUtil {
     final entity = await AssetEntity.fromId(assetId);
     if (entity == null) return 0;
 
-    final file = await entity.file;
-    if (file == null) return 0;
-
-    if (!await file.exists()) {
-      return 0;
-    }
-    try {
+    if (Platform.isAndroid) {
+      final String? path = entity.relativePath;
+      if (path == null) return 0;
+      final file = File("/storage/emulated/0/$path${entity.title}");
+      print("file path: ${await file.path}");
+      if (!await file.exists()) {
+        return 0;
+      }
+      print("file size: ${await file.length()}");
       final double size = (await file.length()) / 1024;
       fileSizeCache[assetId] = size;
+      return size;
+    } else {
+      final file = await entity.file;
+      if (file == null) return 0;
 
-      try {
-        await file.delete();
-      } catch (e) {
-        debugPrint("Delete file error: $e");
+      if (!await file.exists()) {
+        return 0;
       }
+      try {
+        final double size = (await file.length()) / 1024;
+        fileSizeCache[assetId] = size;
+
+        try {
+          await file.delete();
+        } catch (e) {
+          debugPrint("Delete file error: $e");
+        }
 
-      if (size <= 0) {
+        if (size <= 0) {
+          return 0;
+        }
+        return size;
+      } catch (e) {
         return 0;
       }
-      return size;
-    } catch (e) {
-      return 0;
     }
   }
 }