I found solution for android in this post:
In flutter how i can check if location is enabled?
but I still can not find how to check if location is enabled for IOS, I need to have bool, and I need to see if permision is granted, but is location off
I found solution for android in this post:
In flutter how i can check if location is enabled?
but I still can not find how to check if location is enabled for IOS, I need to have bool, and I need to see if permision is granted, but is location off
Here is a package that can check the status of various permissions on Android & iOS
you can use this to check if location is enabled or not, and ask for permission if it is not enabled, this works with the Geolocator package for both android and iOS
static Future<Position> getCurrentLocation(BuildContext context) async {
bool serviceEnabled;
LocationPermission permission;
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Location services are disabled')));
return Future.error('Location services are disabled');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Location permission denied')),
);
Future.error('Location permission denied');
}
}
if (permission == LocationPermission.deniedForever) {
// ignore: use_build_context_synchronously
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text(
'Location permission are permanently denied, kindly enable location permissions in your settings',
)),
);
return Future.error(
'Location permission are permanently denied, kindly enable location permissions in your settings');
}
Position position = await Geolocator.getCurrentPosition();
return position;
}