diff --git a/README.md b/README.md index 70dd01b2ebb78ae76b97f6869be2fa6a2f1057df..4486d17d68677381d5537b05dd1213115a0fb33b 100644 --- a/README.md +++ b/README.md @@ -31,3 +31,10 @@ A cross plattform project for android and ios to log events offline everywhere a - Textfield to show current locally selected and offline available collection - Button "get Collection devices from Sensor" - Button "store Collection devices locally" + + + + +## GNSS +- Checkbox on add event page which activates GNSS locationing. A field shall signal "no fix" or presision in meter. +The fields lat, long, elevation are updated automatically if checkbox is checked. \ No newline at end of file diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 28156baaab9de16fa55fd651a0be37820954df5d..d194cca222c34d6bb4600f5e2c618649b63e6361 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -33,4 +33,6 @@ </application> <!-- Required to fetch data from the internet. --> <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> + <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> </manifest> diff --git a/lib/addevent.dart b/lib/addevent.dart index 64b9bfd5efef12c250ebdb0154e3e657206976fd..c469156b8ae3c3d47421a524dbdcddf5c55622d7 100644 --- a/lib/addevent.dart +++ b/lib/addevent.dart @@ -1,9 +1,35 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'datamodel.dart'; +import 'dart:async'; +import 'package:geolocator/geolocator.dart'; -class AddEvent extends StatelessWidget { +Future<Position> fetchPosition() async { + Position position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); + print(position.longitude); //Output: 80.24599079 + print(position.latitude); //Output: 29.6593457 + print(position.altitude); + + String long = position.longitude.toString(); + String lat = position.latitude.toString(); + String alt = position.altitude.toString(); + + return position; +} + +class AddEvent extends StatefulWidget { + @override + State<AddEvent> createState() => _AddEventPageState(); +} + +class _AddEventPageState extends State<AddEvent> { + final List<bool> _isSelected = [true]; + + @override + void initState() { + super.initState(); + } void _storeCurrentEvent() { final EventStoreInstance storedEvents = EventStoreInstance(); @@ -30,6 +56,7 @@ class AddEvent extends StatelessWidget { final EventStoreInstance storedEvents = EventStoreInstance(); final EventCurrentInstance currentEvent = EventCurrentInstance(); + return Scaffold( appBar: AppBar(title: const Text("Add Event")), body: @@ -51,12 +78,12 @@ class AddEvent extends StatelessWidget { labelText: 'Event Type', ), items: - eventTypes.store.map((EventType event) { - return DropdownMenuItem( - value: event.name, - child: Text(event.name), - ); - }).toList(), + eventTypes.store.map((EventType event) { + return DropdownMenuItem( + value: event.name, + child: Text(event.name), + ); + }).toList(), onChanged: (value) { currentEvent.store.type = value.toString(); } @@ -101,17 +128,36 @@ class AddEvent extends StatelessWidget { decoration: const InputDecoration( labelText: 'Elevation' ), - ) + ), + FutureBuilder<Position>( + future: fetchPosition(), + builder: (context, snapshot){ + if (snapshot.hasData) + { + return Text(snapshot.data!.latitude.toString()); + } + else{ + return CircularProgressIndicator(); + } + } + ), ]), bottomNavigationBar: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - FloatingActionButton( - heroTag: null, - onPressed: null, - tooltip: 'Get GNSS from device', - child: Icon(Icons.my_location), + + ToggleButtons( + children: <Widget>[ + Icon(Icons.my_location), + ], + isSelected: _isSelected, + onPressed: (int index) { + setState(() { + _isSelected[index] = !_isSelected[index]; + }); + }, ), + SizedBox(width: 50), FloatingActionButton( heroTag: null, diff --git a/pubspec.lock b/pubspec.lock index 4fae244ebe64b5c9b145c801bddfc697fc9310c3..5f39eaccdf0f2de11504602898825dc6c361138f 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -93,6 +93,48 @@ packages: description: flutter source: sdk version: "0.0.0" + geolocator: + dependency: "direct main" + description: + name: geolocator + url: "https://pub.dartlang.org" + source: hosted + version: "8.1.1" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + url: "https://pub.dartlang.org" + source: hosted + version: "3.0.2" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + url: "https://pub.dartlang.org" + source: hosted + version: "2.0.1" + geolocator_platform_interface: + dependency: transitive + description: + name: geolocator_platform_interface + url: "https://pub.dartlang.org" + source: hosted + version: "4.0.2" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + url: "https://pub.dartlang.org" + source: hosted + version: "2.1.4" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.0" http: dependency: "direct main" description: @@ -190,35 +232,35 @@ packages: name: shared_preferences url: "https://pub.dartlang.org" source: hosted - version: "2.0.12" + version: "2.0.13" shared_preferences_android: dependency: transitive description: name: shared_preferences_android url: "https://pub.dartlang.org" source: hosted - version: "2.0.10" + version: "2.0.11" shared_preferences_ios: dependency: transitive description: name: shared_preferences_ios url: "https://pub.dartlang.org" source: hosted - version: "2.0.9" + version: "2.0.10" shared_preferences_linux: dependency: transitive description: name: shared_preferences_linux url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.1.0" shared_preferences_macos: dependency: transitive description: name: shared_preferences_macos url: "https://pub.dartlang.org" source: hosted - version: "2.0.2" + version: "2.0.3" shared_preferences_platform_interface: dependency: transitive description: @@ -239,7 +281,7 @@ packages: name: shared_preferences_windows url: "https://pub.dartlang.org" source: hosted - version: "2.0.4" + version: "2.1.0" sky_engine: dependency: transitive description: flutter @@ -307,14 +349,14 @@ packages: name: win32 url: "https://pub.dartlang.org" source: hosted - version: "2.3.6" + version: "2.3.11" xdg_directories: dependency: transitive description: name: xdg_directories url: "https://pub.dartlang.org" source: hosted - version: "0.2.0" + version: "0.2.0+1" sdks: dart: ">=2.15.1 <3.0.0" - flutter: ">=2.5.0" + flutter: ">=2.8.0" diff --git a/pubspec.yaml b/pubspec.yaml index 60438c989cc08d56d04a5ad5b5257092538b6e14..87d46a2fb95778aa223e400d5cb4d34914b47228 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -32,7 +32,7 @@ dependencies: shared_preferences: ^2.0.12 http: ^0.13.4 - + geolocator: ^8.1.1 # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons.