requestLocationPermission static method
Implementation
static Future<bool> requestLocationPermission() async {
try {
final bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
doPrint('Location services are disabled.');
return false;
}
LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
doPrint('Requesting location permission at startup...');
permission = await Geolocator.requestPermission();
}
return permission == LocationPermission.always ||
permission == LocationPermission.whileInUse;
} catch (e) {
doPrint('Error requesting location permission $e');
return false;
}
}