nc-photos/app/lib/mobile/android/permission_util.dart

28 lines
958 B
Dart
Raw Normal View History

import 'package:logging/logging.dart';
import 'package:nc_photos/stream_extension.dart';
2023-08-31 20:34:48 +02:00
import 'package:np_platform_permission/np_platform_permission.dart';
Future<Map<String, int>> requestPermissionsForResult(
2023-09-01 20:15:41 +02:00
List<String> permissions) =>
_doRequest(() => Permission.request(permissions));
Future<Map<String, int>> requestReadExternalStorageForResult() =>
_doRequest(() => Permission.requestReadExternalStorage());
Future<Map<String, int>> requestPostNotificationsForResult() =>
_doRequest(() => Permission.requestPostNotifications());
Future<Map<String, int>> _doRequest(Future Function() op) async {
Map<String, int>? result;
final resultFuture = Permission.stream
.whereType<PermissionRequestResult>()
.first
.then((ev) => result = ev.grantResults);
2023-09-01 20:15:41 +02:00
await op();
await resultFuture;
2023-09-01 20:15:41 +02:00
_log.info("[_doRequest] Result: $result");
return result!;
}
final _log = Logger("mobile.android.permission_util");