Flutter › Maps & Geolocation in Flutter

How should you properly and correctly handle requesting location permissions across the several genuinely different possible permission states, including denied, granted, and permanently denied, using the geolocator or permission_handler packages?

Intermediate

Answer

Properly handling location permissions requires checking the current existing permission status first, then appropriately requesting that permission if it has genuinely not already been granted, and correctly handling each of the several genuinely different possible resulting outcomes, including the user granting that permission, denying it just once, denying it permanently in a way that genuinely requires directing them to their own device settings instead, or the device's own location services being completely disabled entirely at the system level, ensuring your app can properly and gracefully guide the user through resolving whichever particular specific situation actually applies to them.
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
  permission = await Geolocator.requestPermission();
}
if (permission == LocationPermission.deniedForever) {
  await Geolocator.openAppSettings();
}
Real-world example A ride sharing app properly checks the current location permission status before attempting to actually retrieve a rider's own location, correctly guiding them directly to their own device settings if they had previously permanently denied that particular required permission.

Common follow-ups: What genuinely different specific behavior applies to requesting location permission on iOS compared to Android?;How do you actually properly and correctly check whether a device's own location services are actually genuinely enabled at the broader overall system level?