From c62aede3993d032e6357a2cf00651786c9af31df Mon Sep 17 00:00:00 2001
From: Maximilian Betz <Maximilian.Betz@awi.de>
Date: Tue, 1 Mar 2022 11:21:23 +0100
Subject: [PATCH] selecting collection ui works

---
 lib/addevent.dart      |  1 +
 lib/configuration.dart | 35 +++++++++++++++--------------------
 lib/datamodel.dart     | 12 +++++++++++-
 3 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/lib/addevent.dart b/lib/addevent.dart
index 746cb23..370c4f4 100644
--- a/lib/addevent.dart
+++ b/lib/addevent.dart
@@ -109,6 +109,7 @@ class _AddEventPageState extends State<AddEvent>  {
             currentEvent.store.latitude,
             currentEvent.store.longitude,
             currentEvent.store.elevation
+            //TODO: add timestamp! Begin & End
         ));
   }
 
diff --git a/lib/configuration.dart b/lib/configuration.dart
index 84e9492..c5da786 100644
--- a/lib/configuration.dart
+++ b/lib/configuration.dart
@@ -66,8 +66,8 @@ class _MyHomePageState extends State<Configuration> {
 
   @override
   Widget build(BuildContext context) {
-    final CollectionStoreInstance storedCollections = CollectionStoreInstance();
-    final CollectionCurrentInstance currentCollection = CollectionCurrentInstance();
+    final CollectionStoreInstance collections = CollectionStoreInstance();
+    final CollectionCurrentInstance activeCollection = CollectionCurrentInstance();
 
     return Scaffold(
       appBar: AppBar(
@@ -82,26 +82,33 @@ class _MyHomePageState extends State<Configuration> {
                 builder: (context, snapshot){
                   if (snapshot.hasData)
                   {
-                    debugPrint('Got collections:');
+                    collections.store = [];
+
+                    //debugPrint('Got Collections:');
                     snapshot.data?.forEach((element) {
-                      debugPrint(element.id.toString() + ' ' + element.toString() + '   #' + element.description.toString());
+                      //debugPrint(element.id.toString() + ' ' + element.collectionName.toString() + '   #' + element.description.toString());
+                      collections.store.add(element);
                     });
 
+                    /*Initialize active collection with first received collection if not initialized yet*/
+                    if(activeCollection.store.collectionName == ''){
+                      activeCollection.store = collections.store[0];
+                    }
 
                     return DropdownButtonFormField(
-                        value: currentCollection.store.collectionName,
+                        value: activeCollection.store.collectionName,
                         decoration: const InputDecoration(
-                          labelText: 'Chosen Collection',
+                          labelText: 'Chose Collection',
                         ),
                         items:
-                        storedCollections.store.map((Collection collection) {
+                        collections.store.map((Collection collection) {
                           return DropdownMenuItem(
                             value: collection.collectionName,
                             child: Text(collection.collectionName),
                           );
                         }).toList(),
                         onChanged: (value) {
-                          currentCollection.store.collectionName = value.toString();
+                          activeCollection.store = collections.getCollectionFromName(value.toString());
                         }
                     );
                   }
@@ -110,18 +117,6 @@ class _MyHomePageState extends State<Configuration> {
                   }
                 }
             ),
-            FutureBuilder<Collection>(
-                future: futureCollection,
-                builder: (context, snapshot){
-                  if (snapshot.hasData)
-                  {
-                    return Text(snapshot.data!.collectionName);
-                  }
-                  else{
-                    return const CircularProgressIndicator();
-                  }
-                }
-            ),
           ],
         ),
       ),
diff --git a/lib/datamodel.dart b/lib/datamodel.dart
index a81d489..dc5b634 100644
--- a/lib/datamodel.dart
+++ b/lib/datamodel.dart
@@ -109,6 +109,16 @@ class EventType{
 
 abstract class CollectionStoreBase {
   List<Collection> store = [];
+
+  Collection getCollectionFromName(String name) {
+    for (var collection in store) {
+      if (collection.collectionName == name) {
+        return collection;
+      }
+    }
+    throw Exception('Event with name :' + name + ' was not found.');
+  }
+
 }
 
 class CollectionStoreInstance extends CollectionStoreBase {
@@ -157,7 +167,7 @@ abstract class EventCurrentBase{
 }
 
 abstract class CollectionCurrentBase{
-  Collection store = Collection(id: -1, description: 'description', collectionName: 'name');
+  Collection store = Collection(id: -1, description: '', collectionName: '');
 }
 
 abstract class EventTypeStoreBase{
-- 
GitLab