checkPermission method

Future<bool> checkPermission(
  1. KruzrPermission kruzrPermission
)

Checks if a specific permission has been granted.

This method verifies the current status of the specified permission without requesting it from the user. It includes error handling and will throw an error if the permission check fails.

Parameters:

Returns: A Future<bool> that resolves to:

  • true if the permission is already granted
  • false if the permission is not granted or denied

Throws:

  • Exception with message "Unable to check permission" if the underlying permission check fails

Example:

try {
  bool hasLocationPermission = await checkPermission(KruzrPermission.location);
  if (hasLocationPermission) {
    // Permission is granted, proceed with location-based features
  }
} catch (e) {
  // Handle permission check error
  print('Failed to check permission: $e');
}

Implementation

// Permissions
Future<bool> checkPermission(KruzrPermission kruzrPermission) async {
  try {
    return await kruzr_comm.checkPermission(kruzrPermission);
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in checkPermission");
      print(stackTrace);
      print(e);
    }
    return Future.error("Unable to check permission");
  }
}