51 lines
1.8 KiB
Dart

import 'package:geolocator/geolocator.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'location.g.dart';
@riverpod
class MyLocation extends _$MyLocation {
MyLocation() {
/*
bool serviceEnabled;
LocationPermission permission;
// Test if location services are enabled.
serviceEnabled = Geolocator.isLocationServiceEnabled().then(onValue);
if (!serviceEnabled) {
// Location services are not enabled don't continue
// accessing the position and request users of the
// App to enable the location services.
return Future.error('Location services are disabled.');
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
// Permissions are denied, next time you could try
// requesting permissions again (this is also where
// Android's shouldShowRequestPermissionRationale
// returned true. According to Android guidelines
// your App should show an explanatory UI now.
return Future.error('Location permissions are denied');
}
}
if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.
return Future.error(
'Location permissions are permanently denied, we cannot request permissions.');
}*/
}
@override
Future<Position> build() async{
Position l = Position(longitude: 0, latitude: 0,
timestamp: DateTime.timestamp(), accuracy: 0, altitude: 0,
altitudeAccuracy: 0, heading: 0, headingAccuracy: 0,
speed: 0, speedAccuracy: 0);
return Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
}
}