getIOSLocation method

Future<LatLong> getIOSLocation({
  1. required dynamic showSheet(),
  2. required dynamic showSettings(),
})

Implementation

Future<LatLong> getIOSLocation({
  required Function() showSheet,
  required Function() showSettings,
}) async {
  final serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    Logger.e('Location services are disabled.');
    return defaultLocation;
  } else {
    LocationPermission permission = await Geolocator.checkPermission();

    if (permission == LocationPermission.denied) {
      var choice = await showSheet.call();
      if (choice == true) {
        permission = await Geolocator.requestPermission();
        if (permission == LocationPermission.denied) {
          Logger.e('Location permissions are denied');
          return defaultLocation;
        } else if (permission == LocationPermission.deniedForever) {
          Logger.e('Location permissions are denied');
          return defaultLocation;
          // } else if (permission == LocationPermission.unableToDetermine) {
          //   Logger.e('Location permissions are denied');
          //   return defaultLocation;
        } else {
          var pos = await Geolocator.getCurrentPosition();
          return LatLong(lat: pos.latitude, long: pos.longitude);
        }
      } else {
        return defaultLocation;
      }
    } else if (permission == LocationPermission.deniedForever) {
      return defaultLocation;
      // Logger.e('Location permissions are disabled');
      // await showSettings.call();
      // permission = await Geolocator.checkPermission();
      // if (permission == LocationPermission.denied) {
      //   Logger.e('Location permissions are denied');
      //   return defaultLocation;
      // } else if (permission == LocationPermission.deniedForever) {
      //   Logger.e('Location permissions are denied forever');
      //   return defaultLocation;
      //   // } else if (permission == LocationPermission.unableToDetermine) {
      //   //   Logger.e('Location permissions are denied forever');
      //   //   return defaultLocation;
      // } else {
      //   var pos = await Geolocator.getCurrentPosition();
      //   return LatLong(lat: pos.latitude, long: pos.longitude);
      // }
    } else {
      var pos = await Geolocator.getCurrentPosition();
      return LatLong(lat: pos.latitude, long: pos.longitude);
    }
  }
}