let AI comment everything because well... yeah...

This commit is contained in:
Nico
2025-06-06 21:00:32 +02:00
parent 9c84d0c375
commit cc110ac104
44 changed files with 1230 additions and 646 deletions

View File

@@ -1,19 +1,34 @@
// * Service for handling GPS location functionality
// * Provides methods for:
// * - Location permission handling
// * - GPS service status checks
// * - Position determination
// * - Always-on location checks
import 'package:fforte/screens/addCam/exceptions/location_disabled_exception.dart';
import 'package:fforte/screens/addCam/exceptions/location_forbidden_exception.dart';
import 'package:fforte/screens/excursion/exceptions/need_always_location_exception.dart';
import 'package:geolocator/geolocator.dart';
/// Service class for handling all GPS location related functionality
class GeolocatorService {
// determine live position with checks for denied permission and turned off location service
/// Determine the current device position with permission checks
/// @param alwaysOnNeeded Whether the app needs always-on location permission
/// @throws LocationDisabledException if location services are disabled
/// @throws LocationForbiddenException if location permission is denied
/// @throws NeedAlwaysLocation if always-on permission is needed but not granted
/// @return Future<Position> The current GPS position
static Future<Position> deteterminePosition({bool alwaysOnNeeded = false}) async {
bool locationEnabled;
LocationPermission permissionGiven;
// Check if location services are enabled
locationEnabled = await Geolocator.isLocationServiceEnabled();
if (!locationEnabled) {
throw LocationDisabledException();
}
// Check and request location permissions if needed
permissionGiven = await Geolocator.checkPermission();
if (permissionGiven == LocationPermission.denied) {
permissionGiven = await Geolocator.requestPermission();
@@ -22,13 +37,16 @@ class GeolocatorService {
}
}
// Check for always-on permission if required
if (alwaysOnNeeded && permissionGiven != LocationPermission.always) {
throw NeedAlwaysLocation();
}
return await Geolocator.getCurrentPosition();
return await Geolocator.getCurrentPosition();
}
/// Check if always-on location permission is enabled
/// @return Future<bool> True if always-on permission is granted or location is disabled
static Future<bool> alwaysPositionEnabled() async {
LocationPermission permissionGiven = await Geolocator.checkPermission();
bool locationEnabled = await Geolocator.isLocationServiceEnabled();