1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-12-30 14:58:52 +00:00
comunicmobile/lib/utils/permission_utils.dart
2021-03-12 21:19:40 +01:00

27 lines
643 B
Dart

import 'package:comunic/utils/log_utils.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
/// Permission utilities
///
/// @author Pierre Hubert
/// Request a permission, if it has not been granted yet
Future<bool> requestPermission(
BuildContext context, Permission permission) async {
try {
if (await permission.isPermanentlyDenied) {
return false;
}
if (await permission.isGranted) return true;
if (await permission.request() != PermissionStatus.granted) return false;
return true;
} catch (e, s) {
logError(e, s);
return false;
}
}