requestPermissions method
Request the permissions needed for this probe to run. Return true if all permissions are granted. Only used on Android - iOS automatically request permissions when a resource (like the microphone) is accessed.
Implementation
Future<bool> requestPermissions() async {
// fast out if on iOS - permissions are automatically requested
if (Platform.isIOS) return true;
// fast out if already have permissions
if (await arePermissionsGranted()) return true;
debug('$runtimeType - Asking permission for: $permissions');
bool granted = true;
try {
final status = await permissions.request();
debug('$runtimeType - Permission status: $status');
granted = status.values.fold(
true, (value, status) => value && status == PermissionStatus.granted);
} catch (error) {
warning(
'$runtimeType - Error trying to request permissions, error: $error');
return false;
}
return granted;
}