requestPermission static method
Requests storage permission on Android
If you app supports Android 9 or lower, the call to request storage permission is mandatory. Aways returns StoragePermissionStatus.granted on Android 10 or higher and on iOS.
Implementation
static Future<StoragePermissionStatus> requestPermission() async {
if (Platform.isIOS) return StoragePermissionStatus.granted;
try {
final status = await _channel.invokeMethod<bool>(
'checkStoragePermission',
);
if (status == true) return StoragePermissionStatus.granted;
} catch (e) {
debugPrint(e.toString());
return StoragePermissionStatus.unknown;
}
try {
bool? permissionStatus;
await _channel.invokeMethod<bool>('requestStoragePermission');
await for (bool event in _permissionStatusStream.stream) {
permissionStatus = event;
}
if (permissionStatus == null) return StoragePermissionStatus.unknown;
if (permissionStatus) {
return StoragePermissionStatus.granted;
} else {
return StoragePermissionStatus.denied;
}
} catch (e) {
debugPrint(e.toString());
return StoragePermissionStatus.unknown;
}
}