getPermission function

Future<bool> getPermission(
  1. Permission permission, {
  2. required String alert,
  3. GestureTapCallback? cancelTap,
})

单独获取一个权限

Implementation

Future<bool> getPermission(
  Permission permission, {
  required String alert,
  GestureTapCallback? cancelTap,
}) async {
  if (!isMobile) return false;
  PermissionStatus permissionStatus = await permission.status;
  if (permissionStatus.isDenied) {
    PermissionPrompt.show(content: alert);
    permissionStatus = await permission.request();
    pop();
  }
  if (!(permissionStatus.isGranted || permissionStatus.isLimited)) {
    final result = await AlertConfirmCancel(
        text: alert,
        autoClose: false,
        confirmTap: () {
          pop(true);
        },
        cancelTap: () {
          pop(false);
          cancelTap?.call();
        }).show();
    if (result == true) await openAppSettings();
  }
  return permissionStatus.isGranted || permissionStatus.isLimited;
}