All checks were successful
Build and deploy Flutter Web / build (push) Successful in 2m28s
33 lines
913 B
Dart
33 lines
913 B
Dart
import 'package:geolocator/geolocator.dart';
|
|
import 'package:latlong2/latlong.dart';
|
|
|
|
class CurrentLocation {
|
|
Future<LatLng?> resolve() async {
|
|
final serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
|
if (!serviceEnabled) {
|
|
return null;
|
|
}
|
|
|
|
final permission = await _resolvePermission();
|
|
if (permission != LocationPermission.whileInUse &&
|
|
permission != LocationPermission.always) {
|
|
return null;
|
|
}
|
|
|
|
final position = await Geolocator.getCurrentPosition(
|
|
locationSettings: const LocationSettings(accuracy: LocationAccuracy.high),
|
|
);
|
|
|
|
return LatLng(position.latitude, position.longitude);
|
|
}
|
|
|
|
Future<LocationPermission> _resolvePermission() async {
|
|
final permission = await Geolocator.checkPermission();
|
|
if (permission != LocationPermission.denied) {
|
|
return permission;
|
|
}
|
|
|
|
return Geolocator.requestPermission();
|
|
}
|
|
}
|