You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
car_common_app/lib/utils/AppPermissionHandler.dart

67 lines
1.7 KiB
Dart

import 'package:permission_handler/permission_handler.dart';
import 'dialogs_and_bottomsheets.dart';
enum ConfirmAction { CANCEL, ACCEPT }
Future<bool> requestPermissionGranted(
context, Permission requestPermissions) async {
var result = await requestPermissions.request();
switch (result) {
case PermissionStatus.granted:
// Application has been given permission to use the feature.
return true;
case PermissionStatus.denied:
// Application has been denied permission to use the feature.
return false;
case PermissionStatus.permanentlyDenied:
ConfirmAction? res = await showConfirmDialogs(
context,
'You was denied Permission. You have give manual permission from app setting. ',
'Open App Setting',
'Cancel');
if (res == ConfirmAction.ACCEPT) {
return false;
} else if (res == ConfirmAction.CANCEL) {
return false;
}
return false;
case PermissionStatus.restricted:
// iOS has restricted access to a specific feature.
return false;
default:
return false;
}
}
class AppPermissions{
static void location(Function(bool) completion) {
Permission.location.isGranted.then((isGranted){
if(!isGranted){
Permission.location.request().then((granted){
completion(granted == PermissionStatus.granted);
});
}
completion(isGranted);
});
}
static void checkAll(Function(bool) completion){
[
Permission.location
].request().then((value){
bool allGranted = false;
value.values.forEach((element) {
allGranted = allGranted && element == PermissionStatus.granted;
});
completion(allGranted);
});
}
}