Files
fforte/lib/screens/addCam/services/geolocator_service.dart
Nico 9879809857 fixed the location error
the one where no toast is shown
2025-05-09 23:32:40 +02:00

27 lines
1012 B
Dart

import 'package:fforte/screens/addCam/exceptions/location_disabled_exception.dart';
import 'package:fforte/screens/addCam/exceptions/location_forbidden_exception.dart';
import 'package:geolocator/geolocator.dart';
class GeolocatorService {
// determine live position with checks for denied permission and turned off location service
static Future<Position> deteterminePosition() async {
bool locationEnabled;
LocationPermission permissionGiven;
locationEnabled = await Geolocator.isLocationServiceEnabled();
if (!locationEnabled) {
throw LocationDisabledException();
}
permissionGiven = await Geolocator.checkPermission();
if (permissionGiven == LocationPermission.denied) {
permissionGiven = await Geolocator.requestPermission();
if (permissionGiven == LocationPermission.denied || permissionGiven == LocationPermission.deniedForever) {
throw LocationForbiddenException();
}
}
return await Geolocator.getCurrentPosition();
}
}