Kaynağa Gözat

[fix]修复导入全部文件流程

zk 1 yıl önce
ebeveyn
işleme
35352081dc
1 değiştirilmiş dosya ile 28 ekleme ve 8 silme
  1. 28 8
      lib/module/audiopicker/controller.dart

+ 28 - 8
lib/module/audiopicker/controller.dart

@@ -35,22 +35,35 @@ class AudioPickerController extends BaseController {
   @override
   void onReady() async {
     super.onReady();
+    bool isGrant = await checkFilePermission();
+    if (!isGrant) {
+      _onRecordPermissionDenied();
+      return;
+    }
+    _initAudioPathList();
+  }
+
+  void _initAudioPathList() async {
+    currentPath = await initPathEntity();
+    totalCount = await currentPath?.assetCountAsync ?? 0;
+    requestList(0, limit, isClearAll: true);
+  }
+
+  Future<bool> checkFilePermission({void Function()? requestPermission}) async {
     if (!await AudioPickerUtils.hasPermission()) {
       bool isAllow = await _showRequestPermissionDialog();
       if (isAllow) {
         bool permission = await AudioPickerUtils.requestPermissionExtend();
         if (!permission) {
-          _onRecordPermissionDenied();
-          return;
+          return false;
+        } else {
+          requestPermission?.call();
         }
       } else {
-        _onRecordPermissionDenied();
-        return;
+        return false;
       }
     }
-    currentPath = await initPathEntity();
-    totalCount = await currentPath?.assetCountAsync ?? 0;
-    requestList(0, limit, isClearAll: true);
+    return true;
   }
 
   _onRecordPermissionDenied() {
@@ -167,7 +180,14 @@ class AudioPickerController extends BaseController {
     requestList(audioList.length, limit);
   }
 
-  void pickSystemFile() {
+  void pickSystemFile() async {
+    bool isGrant = await checkFilePermission(requestPermission: () {
+      _initAudioPathList();
+    });
+    if (!isGrant) {
+      _onRecordPermissionDenied();
+      return;
+    }
     FileUploadCheckHelper.choicePlatformLocalFileAndCreateOrder(
         choiceSuccessCallback: () {
       Get.back();