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.
		
		
		
		
		
			
		
			
				
	
	
		
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Dart
		
	
			
		
		
	
	
			49 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Dart
		
	
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
 | 
						|
import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.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) {
 | 
						|
    showDialog(
 | 
						|
      context: context,
 | 
						|
      builder: (cxt) => ConfirmDialog(
 | 
						|
        message: "Please provide location permission",
 | 
						|
        onTap: () {
 | 
						|
          if (isPermissionError) {
 | 
						|
            Geolocator.openAppSettings();
 | 
						|
          } else {
 | 
						|
            Geolocator.openLocationSettings();
 | 
						|
          }
 | 
						|
          Navigator.pop(context);
 | 
						|
          // createVacationRule(list);
 | 
						|
        },
 | 
						|
      ),
 | 
						|
    );
 | 
						|
  }
 | 
						|
 | 
						|
  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);
 | 
						|
    });
 | 
						|
  }
 | 
						|
}
 |