Future<void> getAndSaveCountryISOCode() async { LocationPermission permission = await…
- User
Future _getAndSaveCountryISOCode() async { LocationPermission permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied || permission == LocationPermission.deniedForever) { // Request permission if it's denied permission = await Geolocator.requestPermission(); }
if (permission == LocationPermission.denied) { // Handle permission denied showCustomSnackBar( title: "Permission denied", message: "Location permission has been denied. Please enable location permission in the app settings.", duration: 3, okText: "Open Settings", onOkTap: () { Geolocator.openAppSettings(); }, ); return; }
if (permission == LocationPermission.deniedForever) { // Handle permission permanently denied // You might want to show a dialog explaining how to grant permission in settings return; }
try { final position = await Geolocator.getCurrentPosition(); // ... (rest of the code) } catch (e) { appDebugprint("Error in _getAndSaveCountryISOCode: $e"); } }
PlatformException (PlatformException(PERMISSION_DENIED_NEVER_ASK, Location permission denied forever - please open app settings, null, null))
Assistant