check static method

void check(
  1. List<Permission> permissionList, {
  2. String? errMsg,
  3. VoidCallback? onSuccess,
  4. VoidCallback? onFailed,
  5. VoidCallback? onOpenSetting,
})

检查权限

Implementation

static void check(
  List<Permission> permissionList, {
  String? errMsg,
  VoidCallback? onSuccess,
  VoidCallback? onFailed,
  VoidCallback? onOpenSetting,
}) async {
  bool flag = true;
  for (var value in permissionList) {
    var status = await value.status;
    if (!status.isGranted) {
      flag = false;
      break;
    }
  }
  if (!flag) {
    PermissionStatus permissionStatus = await requestPermission(permissionList);
    if (permissionStatus.isGranted) {
      onSuccess != null ? onSuccess() : defaultCall();
    } else if (permissionStatus.isDenied) {
      onFailed != null ? onFailed() : defaultCall();
    } else if (permissionStatus.isPermanentlyDenied) {
      onOpenSetting != null ? onOpenSetting() : defaultCall();
    } else if (permissionStatus.isRestricted) {
      //IOS单独处理
      onOpenSetting != null ? onOpenSetting() : defaultCall();
    } else if (permissionStatus.isLimited) {
      //IOS单独处理
      onOpenSetting != null ? onOpenSetting() : defaultCall();
    }
  }
}