I have problem when user entered google map page without location enabled the map wont updated so i want to check if the user have location enabled beforehand so i need function that return true if location enabled and false if not.
Asked
Active
Viewed 1.5k times
3 Answers
15
ServiceStatus serviceStatus = await PermissionHandler().checkServiceStatus(PermissionGroup.location);
bool enabled = (serviceStatus == ServiceStatus.enabled);
you can also show a rationale for requesting permission (Android only)
bool isShown = await PermissionHandler().shouldShowRequestPermissionRationale(PermissionGroup.location);
var location = Location();
bool enabled = await location.serviceEnabled();
and request to enable it by
bool gotEnabled = await location.requestService();

Mohamed Ali
- 3,717
- 1
- 33
- 39
11
for those who came to this stackoverflow question like myself, there have been changes and updates on PermissionHandler package and the older solutions are now invalid.
you can check if the location service is enabled:
if (await Permission.locationWhenInUse.serviceStatus.isEnabled) {
// Use location.
}

DNS
- 851
- 11
- 19
3
You can install the permission handler plugin and then use it:
final PermissionStatus permission = await PermissionHandler()
.checkPermissionStatus(PermissionGroup.location);

ilBarra
- 796
- 1
- 8
- 25
-
Does it check if the gps is operational and not if the app have location permission? – Michael2411 Jan 06 '19 at 08:41
-
Checks @CopsOnRoad answer here: https://stackoverflow.com/questions/51097428/is-gps-activated-flutter – ilBarra Jan 06 '19 at 08:46
-
It just checks for permission location but not GPS service – Fayaz May 25 '19 at 06:53