I'm using the geolocator package to get the current location of a device. I recently installed a location Spoofer app to test some features .
However, upon using the spoofer, geolocator seems to break? It never returns a location whenever I try to get a location.
How do I resolve this issue? Thank you for your help!
(the problem is that the location no longer returns even after I uninstall the location spoofer. The GPS functions for my app no longer work on the device)
Heres the function I call whenever I try to get a location
Future<Position> getCurrentLocation() async {
bool serviceEnabled;
LocationPermission permission;
Position position;
// ignore: await_only_futures
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
// ignore: await_only_futures
await requestLocation();
serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
callSnackbar('Error', 'Location services are disabled');
return Future.error('Location services are disabled.');
}
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.deniedForever) {
callSnackbar('Error',
'Location permissions are permantly denied, we cannot request permissions');
return Future.error(
'Location permissions are permantly denied, we cannot request permissions.');
}
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission != LocationPermission.whileInUse &&
permission != LocationPermission.always) {
callSnackbar('Error',
'Location permissions are denied (actual value: $permission)');
return Future.error(
'Location permissions are denied (actual value: $permission).');
}
}
print('LOGIC');
position = await Geolocator.getCurrentPosition();
if (position == null) {
print('null');
} else {
print('LOCATION');
print(position);
}
return position;
}
and heres an example of me calling the function:
getCurrentLocation().then((contents) {
print('getting location');
print(contents.latitude);
);
}, onError: (e) {}).timeout(const Duration(seconds: 5),
onTimeout: () {
callSnackbar('Error', 'Couldn\'t get location');
});
the above code works fine until I install and use a location spoofer app. So even after the uninstall, the app no longer works and just timeouts because the future does not return.