Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from EmmanuelTobi/master
Location Permission feature setups and implementations for PetShop
- Loading branch information
Showing
3 changed files
with
147 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:geolocation/geolocation.dart'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
|
||
class PermissionUtil { | ||
|
||
// Allows request any permission in the Permission Group with this method | ||
static Future<bool> requestPermission(PermissionGroup permission) async { | ||
final PermissionHandler _permissionHandler = PermissionHandler(); | ||
_permissionHandler.shouldShowRequestPermissionRationale(permission); | ||
final result = await _permissionHandler.requestPermissions([permission]); | ||
if (result[permission] == PermissionStatus.granted) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// Allows checks on any permission in the Permission Group with this method | ||
static Future<bool> hasPermission(PermissionGroup permission) async { | ||
final PermissionHandler _permissionHandler = PermissionHandler(); | ||
var permissionStatus = await _permissionHandler.checkPermissionStatus(permission); | ||
return permissionStatus == PermissionStatus.granted; | ||
} | ||
|
||
//below is about gps and location services checks | ||
|
||
static Future<bool> isGpsServiceActive() async { | ||
final GeolocationResult gps = await Geolocation.isLocationOperational(); | ||
if(!gps.isSuccessful) { | ||
await Geolocation.enableLocationServices() | ||
.then((GeolocationResult onValue) async { | ||
if (onValue.isSuccessful) return true; | ||
else return false; | ||
}); | ||
} | ||
return true; | ||
} | ||
|
||
static Future<bool> isLocationServiceAndPermissionsActive() async { | ||
final GeolocationResult gpsServiceActive = await Geolocation.isLocationOperational(); | ||
final gpsPermissionGranted = await PermissionUtil.hasPermission(PermissionGroup.locationWhenInUse); | ||
|
||
if(gpsServiceActive.isSuccessful == false || gpsPermissionGranted == false) | ||
return false; | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters