feat: consolidate backend and docker-compose setup
This commit is contained in:
commit
ff3753a745
306 files changed
+35450
No files matched your search
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
|
||||
class LocationService {
|
||||
static Future<Position?> Function()? mockDeterminator;
|
||||
|
||||
static Future<Position?> determinePosition() async {
|
||||
if (mockDeterminator != null) {
|
||||
return mockDeterminator!();
|
||||
}
|
||||
try {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
debugPrint('Location services are disabled.');
|
||||
return null;
|
||||
}
|
||||
|
||||
LocationPermission permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
debugPrint('Location permission denied.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
debugPrint('Location permission denied forever.');
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high,
|
||||
timeLimit: const Duration(seconds: 5),
|
||||
);
|
||||
} catch (e) {
|
||||
debugPrint('getCurrentPosition failed: $e. Attempting getLastKnownPosition...');
|
||||
return await Geolocator.getLastKnownPosition();
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Error in LocationService: $e');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user