diff --git a/lib/addevent.dart b/lib/addevent.dart index 955353675cfa734828b3ac80cd6fe85433473226..9b0da635ae0e3764905074563538d0ed241f80a9 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -5,15 +5,15 @@ import 'dart:async'; import 'package:geolocator/geolocator.dart'; class AddEvent extends StatefulWidget { + const AddEvent({Key? key}) : super(key: key); + @override State<AddEvent> createState() => _AddEventPageState(); } class _AddEventPageState extends State<AddEvent> { - bool disableGnssEditing = true; + bool disableGNSSEditing = true; final List<bool> _isGNSSSelected = [true]; - bool servicestatus = false; - bool haspermission = false; late LocationPermission permission; late Position position; late String long = ""; @@ -27,24 +27,9 @@ class _AddEventPageState extends State<AddEvent> { ); getLocation() async { - position = - await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); - print('Get Location: Lat:' + position.latitude.toString() + - ' Long:' + position.longitude.toString() + - ' Alt:' + position.altitude.toString()); - - long = position.longitude.toString(); - lat = position.latitude.toString(); - alt = position.altitude.toString(); - accuracy = position.accuracy; - - if (mounted){ - setState(() { - //refresh UI - });}; StreamSubscription<Position> positionStream = Geolocator.getPositionStream( locationSettings: locationSettings).listen((Position position) { - print('Get Location: Lat:' + position.latitude.toString() + + debugPrint('Get Location: Lat:' + position.latitude.toString() + ' Long:' + position.longitude.toString() + ' Alt:' + position.altitude.toString()); @@ -54,38 +39,39 @@ class _AddEventPageState extends State<AddEvent> { accuracy = position.accuracy; - if (disableGnssEditing == true) { + if (disableGNSSEditing == true) { if(mounted){ setState(() { //refresh UI on update - });}; + });} }; }); } - startGNSS() async { - print("CheckGnssPermission"); - servicestatus = await Geolocator.isLocationServiceEnabled(); - if(servicestatus){ + debugPrint("Check Location Permission"); + bool serviceStatus = false; + bool hasPermission = false; + serviceStatus = await Geolocator.isLocationServiceEnabled(); + if(serviceStatus){ permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.denied) { - print('Location permissions are denied'); + debugPrint('Location permissions are denied'); }else if(permission == LocationPermission.deniedForever){ - print('Location permissions are permanently denied'); + debugPrint('Location permissions are permanently denied'); }else{ - haspermission = true; + hasPermission = true; } }else{ - haspermission = true; + hasPermission = true; } - if(haspermission){ - print('Location permissions granted'); - if(this.mounted){ + if(hasPermission){ + debugPrint('Location permissions granted'); + if(mounted){ setState(() { //refresh the UI });}; @@ -93,12 +79,12 @@ class _AddEventPageState extends State<AddEvent> { getLocation(); } }else{ - print("GPS Service is not enabled, turn on GPS location"); + debugPrint("GPS Service is not enabled, turn on GPS location"); } - if(this.mounted){ + if(mounted){ setState(() { //refresh the UI - });}; + });} } @override @@ -132,9 +118,8 @@ class _AddEventPageState extends State<AddEvent> { final EventCurrentInstance currentEvent = EventCurrentInstance(); String gnssStatusText = ""; - if (true == disableGnssEditing){ - - // Update current event coordinates + if (true == disableGNSSEditing){ + // Update current event coordinates from GNSS stream currentEvent.store.latitude = lat; currentEvent.store.longitude = long; currentEvent.store.elevation = alt; @@ -147,8 +132,7 @@ class _AddEventPageState extends State<AddEvent> { } } else{ - // Just display old event coordinates - gnssStatusText = "GNSS Disabled"; + gnssStatusText = "GNSS Disabled"; // Just display existing event coordinates } return Scaffold( @@ -210,7 +194,7 @@ class _AddEventPageState extends State<AddEvent> { ), TextField( readOnly: false, - enabled: !disableGnssEditing, + enabled: !disableGNSSEditing, //controller: _controllerLat, controller: TextEditingController(text: currentEvent.store.latitude.toString()), decoration: const InputDecoration( @@ -220,7 +204,7 @@ class _AddEventPageState extends State<AddEvent> { ), TextField( readOnly: false, - enabled: !disableGnssEditing, + enabled: !disableGNSSEditing, controller: TextEditingController(text: currentEvent.store.longitude.toString()), decoration: const InputDecoration( labelText: 'Longitude', @@ -229,7 +213,7 @@ class _AddEventPageState extends State<AddEvent> { ), TextField( readOnly: false, - enabled: !disableGnssEditing, + enabled: !disableGNSSEditing, controller: TextEditingController(text: currentEvent.store.elevation.toString()), decoration: const InputDecoration( labelText: 'Elevation', @@ -250,7 +234,7 @@ class _AddEventPageState extends State<AddEvent> { onPressed: (int index) { setState(() { _isGNSSSelected[index] = !_isGNSSSelected[index]; - disableGnssEditing = _isGNSSSelected[index]; + disableGNSSEditing = _isGNSSSelected[index]; }); }, ),