import 'package:geolocator/geolocator.dart'; class LocationService { static Future getCurrentLocation() async { bool serviceEnabled; LocationPermission permission; // Check if location services are enabled serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { return Future.error('Location services are disabled.'); } // Check for permission permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { return Future.error('Location permissions are denied'); } } if (permission == LocationPermission.deniedForever) { return Future.error( 'Location permissions are permanently denied.'); } // Get current location return await Geolocator.getCurrentPosition( desiredAccuracy: LocationAccuracy.high); } }