requestPermission function

Future<bool> requestPermission(
  1. KruzrPermission p
)

Requests a specific permission from the user.

This method displays the system permission dialog to the user and waits for their response. It should be called when the permission is required for app functionality.

Parameters:

Returns: A Future<bool> that resolves to:

  • true if the user granted the permission
  • false if the user denied the permission or the request failed

Note:

  • On some platforms, if a permission was previously denied with "don't ask again", this method may return false immediately without showing a dialog.
  • Consider using ensurePermissionOrOpenSettings for a more comprehensive permission handling flow.

Example:

bool granted = await requestPermission(KruzrPermission.camera);
if (granted) {
  // Permission granted, can use camera features
} else {
  // Permission denied, show alternative or explanation
}

Implementation

Future<bool> requestPermission(KruzrPermission p) async {
  final bool? res = await platform.invokeMethod<bool>('requestPermission', {
    'permission': p.name,
  });
  return res ?? false;
}