Ver código fonte

[fit]修复照片详细bug,增加toast

云天逵 9 meses atrás
pai
commit
f7dbf8a917

+ 4 - 2
lib/module/analysis/analysis_controller.dart

@@ -1,3 +1,4 @@
+import 'dart:io';
 import 'dart:math';
 
 import 'package:classify_photo/classify_photo.dart';
@@ -229,7 +230,8 @@ class AnalysisController extends BaseController {
         imageList.where((asset) => selectedAssets.contains(asset.id)).toList();
 
     for (var asset in assetsToDelete) {
-      FileUtils.deleteAsset(FileType.analysis, asset.id.substring(0, 36));
+
+      FileUtils.deleteAsset(FileType.analysis, Platform.isIOS ? asset.id.substring(0, 36) : asset.id);
     }
 
     selectedTotalSize.value = 0;
@@ -253,7 +255,7 @@ class AnalysisController extends BaseController {
 // 开启图库
   Future<void> openGallery() async {
     var status = await Permission.photos.status;
-    if (status == PermissionStatus.granted) {
+    if (status == PermissionStatus.denied) {
       List<AssetEntity> assets = <AssetEntity>[];
       for (var asset in imageList) {
         var newAsset = await asset.toAssetEntity();

+ 1 - 3
lib/module/calendar/preview/calendar_preview_view.dart

@@ -116,16 +116,14 @@ class CalendarPreviewPage extends BasePage<CalendarPreviewController> {
                                             height: 392.h,
                                             fit: BoxFit.cover,
                                             isOriginal: true,
-                                      loadingBuilder: (context,child,loadingProgress){
 
-                                      }
                                             // errorBuilder:
                                             //     (context, error, stackTrace) {
                                             //   debugPrint(
                                             //       'AssetEntityImage error $error');
                                             //   return Container();
                                             // },
-                                            // frameBuilder: Styles.animFrameBuilder(),
+                                            frameBuilder: Styles.animFrameBuilder(),
                                           )),
                             if (horizontalOffsetPercentage != 0)
                               Positioned(

+ 2 - 1
lib/module/photo_info/photo_info_controller.dart

@@ -1,3 +1,4 @@
+import 'dart:io';
 import 'dart:math';
 
 import 'package:classify_photo/classify_photo.dart';
@@ -152,7 +153,7 @@ class PhotoInfoController extends BaseController {
             CupertinoActionSheetAction(
               onPressed: () {
                 Navigator.pop(context);
-                FileUtils.deleteAsset(type.value, asset.id.substring(0, 36));
+                FileUtils.deleteAsset(type.value, Platform.isIOS ? asset.id.substring(0, 36) : asset.id);
 
                 if (type.value == FileType.privacy) {
                   PrivacyState.removeAsset(asset.id);

+ 1 - 1
lib/module/privacy/privacy_controller.dart

@@ -379,7 +379,7 @@ class PrivacyController extends BaseController {
         imageList.where((asset) => selectedAssets.contains(asset.id)).toList();
 
     for (var asset in assetsToDelete) {
-      FileUtils.deleteAsset(FileType.privacy, asset.id.substring(0, 36));
+      FileUtils.deleteAsset(FileType.privacy, Platform.isIOS ? asset.id.substring(0, 36) : asset.id);
     }
 
     selectedTotalSize.value = 0;

+ 1 - 1
lib/utils/file_utils.dart

@@ -33,7 +33,7 @@ class FileUtils {
   static Future<AssetEntity?> saveAsset(FileType type, AssetEntity asset) async {
     try {
       final assetPath = await getAssetPath(type);
-      final title = asset.id.substring(0, 36);
+      final title= Platform.isIOS ? asset.id.substring(0, 36) : asset.id;
       final assetFile = File('$assetPath/$title.json');
 
       // // 将 AssetEntity 转换为 AssetInfo 后再序列化

+ 42 - 32
lib/utils/image_util.dart

@@ -3,6 +3,7 @@ import 'dart:typed_data';
 
 import 'package:clean/model/asset_info.dart';
 import 'package:clean/module/image_picker/image_picker_util.dart';
+import 'package:clean/utils/toast_util.dart';
 import 'package:intl/intl.dart';
 import 'package:wechat_assets_picker/wechat_assets_picker.dart';
 
@@ -11,7 +12,6 @@ import 'file_utils.dart';
 import 'package:exif/exif.dart';
 
 class ImageUtil {
-
   // 生成月份 key (用于内部存储)
   static String getMonthKey(DateTime date) {
     return '${date.year}-${date.month.toString().padLeft(2, '0')}';
@@ -39,7 +39,8 @@ class ImageUtil {
   }
 
   // 获取指定月份的图片
-  static List<AssetInfo> getMonthAssets(Map<String, List<AssetInfo>> assets, int index) {
+  static List<AssetInfo> getMonthAssets(
+      Map<String, List<AssetInfo>> assets, int index) {
     final monthKeys = assets.keys.toList()
       ..sort((a, b) => b.compareTo(a)); // 最新的月份在前
 
@@ -50,10 +51,12 @@ class ImageUtil {
   }
 
   // 获取缩略图数据
-  static Future<Uint8List?> getImageThumbnail(FileType type, AssetInfo asset) async {
+  static Future<Uint8List?> getImageThumbnail(
+      FileType type, AssetInfo asset) async {
     try {
       // 先尝试从本地读取缩略图
-      final localThumb = await FileUtils.getThumbData(type, asset.id.substring(0, 36));
+      final localThumb = await FileUtils.getThumbData(
+          type, Platform.isIOS ? asset.id.substring(0, 36) : asset.id);
       if (localThumb != null) {
         return localThumb;
       }
@@ -71,7 +74,8 @@ class ImageUtil {
     try {
       // 先尝试从本地读取
       final assetPath = await FileUtils.getAssetPath(type);
-      final localFile = File('$assetPath/${asset.id.substring(0, 36)}.PNG');
+      final localFile = File(
+          '$assetPath/${Platform.isIOS ? asset.id.substring(0, 36) : asset.id}.PNG');
       if (await localFile.exists()) {
         return localFile;
       }
@@ -116,33 +120,38 @@ class ImageUtil {
       final path = asset.originalPath;
       // final file = await asset.file;
       if (path != null && path.isNotEmpty) {
-
-        final file = File(path);
-        // 读取 EXIF 数据
-        final bytes = await file.readAsBytes();
-        final exifData = await readExifFromBytes(bytes);
-
-        if (exifData.isNotEmpty) {
-          // 相机信息
-          details['make'] = exifData['Image Make']?.printable;
-          details['model'] = exifData['Image Model']?.printable;
-
-          // 拍摄参数
-          // 光圈值
-          details['aperture'] = exifData['EXIF FNumber']?.printable;
-          // 快门速度/曝光时间
-          details['exposureTime'] = exifData['EXIF ExposureTime']?.printable;
-          // ISO感光度
-          details['iso'] = exifData['EXIF ISOSpeedRatings']?.printable;
-          // 焦距
-          details['focalLength'] = exifData['EXIF FocalLengthIn35mmFilm']?.printable;
-
-          // GPS 信息
-          if (exifData.containsKey('GPS GPSLatitude') &&
-              exifData.containsKey('GPS GPSLongitude')) {
-            details['latitude'] = exifData['GPS GPSLatitude']?.printable;
-            details['longitude'] = exifData['GPS GPSLongitude']?.printable;
+        try {
+          final file = File(path);
+          // 读取 EXIF 数据
+          final bytes = await file.readAsBytes();
+          final exifData = await readExifFromBytes(bytes);
+
+          if (exifData.isNotEmpty) {
+            // 相机信息
+            details['make'] = exifData['Image Make']?.printable;
+            details['model'] = exifData['Image Model']?.printable;
+
+            // 拍摄参数
+            // 光圈值
+            details['aperture'] = exifData['EXIF FNumber']?.printable;
+            // 快门速度/曝光时间
+            details['exposureTime'] = exifData['EXIF ExposureTime']?.printable;
+            // ISO感光度
+            details['iso'] = exifData['EXIF ISOSpeedRatings']?.printable;
+            // 焦距
+            details['focalLength'] =
+                exifData['EXIF FocalLengthIn35mmFilm']?.printable;
+
+            // GPS 信息
+            if (exifData.containsKey('GPS GPSLatitude') &&
+                exifData.containsKey('GPS GPSLongitude')) {
+              details['latitude'] = exifData['GPS GPSLatitude']?.printable;
+              details['longitude'] = exifData['GPS GPSLongitude']?.printable;
+            }
           }
+        } catch (e) {
+          print('读取 EXIF 数据失败: $e');
+          ToastUtil.show('获取照片详情失败');
         }
       }
 
@@ -150,6 +159,7 @@ class ImageUtil {
       return details;
     } catch (e) {
       print('获取照片详情失败: $e');
+
       return {};
     }
   }
@@ -196,4 +206,4 @@ class ImageUtil {
     }
     return '${value}s';
   }
-}
+}