requestPermission function
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:
p: The KruzrPermission to request from the user.
Returns: A Future<bool> that resolves to:
trueif the user granted the permissionfalseif 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
falseimmediately 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;
}