permissionCheck method

Future<bool> permissionCheck ()

permission check

Implementation

Future<bool> permissionCheck() async {
  PermissionHandler pHandler = PermissionHandler();
  List<PermissionGroup> requestPermission = [];

  /// 摄像机
  if (await pHandler.checkPermissionStatus(PermissionGroup.camera) !=
      PermissionStatus.granted) {
    requestPermission.add(PermissionGroup.camera);
  }

  /// 文件读写
  if (await pHandler.checkPermissionStatus(PermissionGroup.storage) !=
      PermissionStatus.granted) {
    if (defaultTargetPlatform == TargetPlatform.android)
      requestPermission.add(PermissionGroup.storage);
  }

  /// 麦克风
  if (await pHandler.checkPermissionStatus(PermissionGroup.microphone) !=
      PermissionStatus.granted) {
    requestPermission.add(PermissionGroup.microphone);
  }

  if (requestPermission.length > 0) {
    Map<PermissionGroup, PermissionStatus> res =
        await pHandler.requestPermissions(requestPermission);
    bool enable = true;
    res.forEach((var p, PermissionStatus status) {
      if (status != PermissionStatus.granted) {
        enable = false;
        return;
      }
    });
    _permissionEnable = enable;
    return _permissionEnable;
  } else {
    _permissionEnable = true;
    return _permissionEnable;
  }
}