Files
daily_mobileapp_customer/lib/service/location/location.dart
2026-05-26 18:01:57 +05:30

33 lines
997 B
Dart

import 'package:geolocator/geolocator.dart';
class LocationService {
static Future<Position> 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);
}
}