Browse Source

文件删除逻辑优化

gjh 1 week ago
parent
commit
c11688c0af

+ 6 - 4
android/app/src/main/java/com/eitchsyh/instrument/eitc_erm_dental_flutter/FileController.java

@@ -284,11 +284,12 @@ public class FileController implements MethodChannel.MethodCallHandler
284
                                 .getContentResolver()
284
                                 .getContentResolver()
285
                                 .delete(uri, null, null);
285
                                 .delete(uri, null, null);
286
                         Log.d(TAG, "删除的数量=" + deleted);
286
                         Log.d(TAG, "删除的数量=" + deleted);
287
-                        if (deleted <= 0)
287
+                        //有些设备即便删除成功了也会返回0,所以去掉判断
288
+                        /*if (deleted <= 0)
288
                         {
289
                         {
289
                             result.error("304", "删除失败", new Exception("删除失败"));
290
                             result.error("304", "删除失败", new Exception("删除失败"));
290
                             return;
291
                             return;
291
-                        }
292
+                        }*/
292
                         result.success(null);
293
                         result.success(null);
293
                     }
294
                     }
294
                     //捕获权限异常,请求权限
295
                     //捕获权限异常,请求权限
@@ -351,14 +352,15 @@ public class FileController implements MethodChannel.MethodCallHandler
351
                         .getContentResolver()
352
                         .getContentResolver()
352
                         .delete(uri, null, null);
353
                         .delete(uri, null, null);
353
                 Log.d(TAG, "删除的数量=" + deleted);
354
                 Log.d(TAG, "删除的数量=" + deleted);
354
-                if (deleted <= 0)
355
+                //有些设备即便删除成功了也会返回0,所以去掉判断
356
+                /*if (deleted <= 0)
355
                 {
357
                 {
356
                     if (result != null)
358
                     if (result != null)
357
                     {
359
                     {
358
                         result.error("304", "删除失败", new Exception("删除失败"));
360
                         result.error("304", "删除失败", new Exception("删除失败"));
359
                     }
361
                     }
360
                     return;
362
                     return;
361
-                }
363
+                }*/
362
                 if (result != null)
364
                 if (result != null)
363
                 {
365
                 {
364
                     result.success(null);
366
                     result.success(null);

+ 6 - 6
lib/pages/history/vm/history_view_model.dart

@@ -77,9 +77,9 @@ class HistoryList extends _$HistoryList {
77
       return false;
77
       return false;
78
     }
78
     }
79
     bool isSuccess = true;
79
     bool isSuccess = true;
80
-    try {
81
-      var stream = Stream.fromIterable(list);
82
-      await for (HistoryItemInfo info in stream) {
80
+    var stream = Stream.fromIterable(list);
81
+    await for (HistoryItemInfo info in stream) {
82
+      try {
83
         logd("历史记录删除文件${info.path}");
83
         logd("历史记录删除文件${info.path}");
84
         await fileChannel.invokeMethod("deleteFile", info.path);
84
         await fileChannel.invokeMethod("deleteFile", info.path);
85
         if (info.type == 0) {
85
         if (info.type == 0) {
@@ -87,10 +87,10 @@ class HistoryList extends _$HistoryList {
87
         } else {
87
         } else {
88
           state.value!.videoList.remove(info);
88
           state.value!.videoList.remove(info);
89
         }
89
         }
90
+      } catch (e) {
91
+        loge("删除单个历史文件异常", error: e);
92
+        isSuccess = false;
90
       }
93
       }
91
-    } catch (e) {
92
-      loge("历史记录页面批量删除异常", error: e);
93
-      isSuccess = false;
94
     }
94
     }
95
     ref.notifyListeners();
95
     ref.notifyListeners();
96
     ref.invalidate(historySelectedCountProvider);
96
     ref.invalidate(historySelectedCountProvider);