requestPermission static method

Future<PermissionStatus> requestPermission(
  1. Permission permission, {
  2. SuccessCallBack? success,
  3. DeniedCallBack? denied,
  4. OtherCallBack? other,
})

请求权限 Permission 请求的权限 success 授权成功回调 denied 授权失败回调; isPermanentlyDenied 是否永久拒绝 other 其他回调

Implementation

static Future<PermissionStatus> requestPermission(
  Permission permission, {
  SuccessCallBack? success,
  DeniedCallBack? denied,
  OtherCallBack? other,
}) async {
  var status = await permission.request();
  if (status == PermissionStatus.granted) {
    success?.call();
  } else if (status == PermissionStatus.denied || status == PermissionStatus.restricted) {
    denied?.call(status.isPermanentlyDenied);
  } else {
    other?.call(status);
  }
  return status;
}