location has been enabled in addition to sending the domain
This commit is contained in:
24
lib/core/location/location_service.dart
Normal file
24
lib/core/location/location_service.dart
Normal file
@@ -0,0 +1,24 @@
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
class LocationService {
|
||||
Future<Position?> getCurrentPosition() async {
|
||||
// 1) service enabled?
|
||||
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) return null;
|
||||
|
||||
// 2) permission
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
}
|
||||
if (permission == LocationPermission.denied ||
|
||||
permission == LocationPermission.deniedForever) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3) get location (geolocator v13+ API)
|
||||
return Geolocator.getCurrentPosition(
|
||||
locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user