Selaa lähdekoodia

文件删除逻辑优化

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

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

@@ -77,9 +77,9 @@ class HistoryList extends _$HistoryList {
77 77
       return false;
78 78
     }
79 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 83
         logd("历史记录删除文件${info.path}");
84 84
         await fileChannel.invokeMethod("deleteFile", info.path);
85 85
         if (info.type == 0) {
@@ -87,10 +87,10 @@ class HistoryList extends _$HistoryList {
87 87
         } else {
88 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 95
     ref.notifyListeners();
96 96
     ref.invalidate(historySelectedCountProvider);