|
|
|
|
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/widgets/bottom_sheets/confirm_bottom_sheet.dart';
|
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
|
|
import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
|
|
|
|
|
class AppPermissions {
|
|
|
|
|
static void location(Function(bool) completion, BuildContext context) {
|
|
|
|
|
Permission.location.isGranted.then((isGranted){
|
|
|
|
|
if(!isGranted){
|
|
|
|
|
Permission.location.request().then((granted){
|
|
|
|
|
completion(granted == PermissionStatus.granted);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
completion(isGranted);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void showErrorLocationDialog(bool isPermissionError, BuildContext context) {
|
|
|
|
|
ConfirmBottomSheet.show(
|
|
|
|
|
context,
|
|
|
|
|
message: LocaleKeys.pleaseProvideLocationPermission.tr(),
|
|
|
|
|
confirmText: LocaleKeys.openSettings.tr(),
|
|
|
|
|
showCancelButton: false,
|
|
|
|
|
onConfirm: () {
|
|
|
|
|
if (isPermissionError) {
|
|
|
|
|
Geolocator.openAppSettings();
|
|
|
|
|
} else {
|
|
|
|
|
Geolocator.openLocationSettings();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|