begin cleanup add_cam_main. dont remember if anything more
This commit is contained in:
26
lib/screens/addCam/services/geolocator_service.dart
Normal file
26
lib/screens/addCam/services/geolocator_service.dart
Normal file
@@ -0,0 +1,26 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user