determinePosition function

Future<Position> determinePosition()

origin: simlpu_mob/lib/globals.dart (determinePosition) author: anovsiradj, opencode-go/glm-5.2 version: 2022-05-31, revised: 2026-08-17

Permission-aware current-position. Throws Future.error if service disabled / permission denied. Ref: https://pub.dev/packages/geolocator

Implementation

Future<Position> determinePosition() async {
  bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
  if (!serviceEnabled) {
    return Future.error('Location services are disabled.');
  }

  LocationPermission 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, we cannot request permissions.');
  }

  return await Geolocator.getCurrentPosition();
}