From 0045f696a22830b4248cb2c850586d60f04bdc75 Mon Sep 17 00:00:00 2001
From: Maximilian Betz <Maximilian.Betz@awi.de>
Date: Fri, 25 Mar 2022 12:46:30 +0100
Subject: [PATCH] some ui improvements

---
 lib/configuration.dart | 304 +++++++++++++++++++++--------------------
 lib/viewevents.dart    |   2 +-
 2 files changed, 158 insertions(+), 148 deletions(-)

diff --git a/lib/configuration.dart b/lib/configuration.dart
index 5cb7416..fb865d4 100644
--- a/lib/configuration.dart
+++ b/lib/configuration.dart
@@ -44,160 +44,170 @@ class _MyHomePageState extends State<Configuration> {
     final EventStoreInstance events = EventStoreInstance();
 
     return Scaffold(
-      appBar: AppBar(
-        title: const Text('Configuration'),
-      ),
-      body: Center(
-        child: Column(
-          mainAxisAlignment: MainAxisAlignment.center,
-          children: <Widget>[
-            const Text(
-                'You must be online to do something here!',
-                style: TextStyle(fontSize: 14)
-            ),
-            const SizedBox(height: 50),
-            TextFormField(
-              keyboardType: TextInputType.emailAddress,
-              autofocus: false,
-              initialValue: configuration.loginInformation.mail,
-              decoration: const InputDecoration(
-                labelText: 'Sensor E-Mail',
-                hintText: 'User for writing events',
-              ),
-              onChanged: (value) {
-                configuration.loginInformation.mail = value;
-              },
-              onFieldSubmitted: (value) {
-                futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
-              },
-            ),
-            TextFormField(
-              autofocus: false,
-              initialValue: configuration.loginInformation.password,
-              decoration: const InputDecoration(
-                labelText: 'Sensor Password',
-                hintText: 'Password for writing events',
-              ),
-              onChanged: (value){
-                configuration.loginInformation.password = value;
-              },
-              onFieldSubmitted: (value) {
-                futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
-              },
-            ),
-            const SizedBox(height: 50),
-            FutureBuilder<List<Collection>>(
-                future: futureCollections,
-                builder: (context, snapshot){
-                  if (snapshot.hasData)
-                  {
-                    configuration.collections = [];
-                    snapshot.data?.forEach((element) {
-                      configuration.collections.add(element);
-                    });
-
-                    /*Initialize active collection with first received
+        appBar: AppBar(
+          title: const Text('Configuration'),
+        ),
+        body: Container(
+          margin: const EdgeInsets.symmetric(horizontal: 5.0),
+          child:
+          Center(
+            child: Column(
+              mainAxisAlignment: MainAxisAlignment.center,
+              children: <Widget>[
+                const Text(
+                    'You must be online to do something here!',
+                    style: TextStyle(fontSize: 14)
+                ),
+                const SizedBox(height: 50),
+                TextFormField(
+                  keyboardType: TextInputType.emailAddress,
+                  autofocus: false,
+                  initialValue: configuration.loginInformation.mail,
+                  decoration: const InputDecoration(
+                    labelText: 'Sensor E-Mail',
+                    hintText: 'User for writing events',
+                  ),
+                  onChanged: (value) {
+                    configuration.loginInformation.mail = value;
+                  },
+                  onFieldSubmitted: (value) {
+                    futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
+                  },
+                ),
+                TextFormField(
+                  autofocus: false,
+                  initialValue: configuration.loginInformation.password,
+                  decoration: const InputDecoration(
+                    labelText: 'Sensor Password',
+                    hintText: 'Password for writing events',
+                  ),
+                  onChanged: (value){
+                    configuration.loginInformation.password = value;
+                  },
+                  onFieldSubmitted: (value) {
+                    futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
+                  },
+                ),
+                const SizedBox(height: 50),
+                FutureBuilder<List<Collection>>(
+                    future: futureCollections,
+                    builder: (context, snapshot){
+                      if (snapshot.hasData)
+                      {
+                        configuration.collections = [];
+                        snapshot.data?.forEach((element) {
+                          configuration.collections.add(element);
+                        });
+
+                        /*Initialize active collection with first received
                     collection if not initialized yet*/
-                    if(configuration.currentCollection.id == -1){
-                      configuration.currentCollection = configuration.collections[0];
-                      futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
-                    }
-
-                    return DropdownButtonFormField(
-                        value: configuration.currentCollection.collectionName,
-                        decoration: const InputDecoration(
-                          labelText: 'Chose Collection',
-                        ),
-                        items:
-                        configuration.collections.map((Collection collection) {
-                          return DropdownMenuItem(
-                            value: collection.collectionName,
-                            child: Text(collection.collectionName),
-                          );
-                        }).toList(),
-                        onChanged: (value) {
-                          configuration.currentCollection = configuration.getCollectionFromName(value.toString());
-                          //Fetch new selected collection devices
+                        if(configuration.currentCollection.id == -1){
+                          configuration.currentCollection = configuration.collections[0];
                           futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
                         }
-                    );
-                  }
-                  else{
-                    return const CircularProgressIndicator();
-                  }
-                }
+
+                        return DropdownButtonFormField(
+                            value: configuration.currentCollection.collectionName,
+                            decoration: const InputDecoration(
+                              labelText: 'Chose Collection',
+                            ),
+                            items:
+                            configuration.collections.map((Collection collection) {
+                              return DropdownMenuItem(
+                                value: collection.collectionName,
+                                child: Text(collection.collectionName),
+                              );
+                            }).toList(),
+                            onChanged: (value) {
+                              configuration.currentCollection = configuration.getCollectionFromName(value.toString());
+                              //Fetch new selected collection devices
+                              futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
+                            }
+                        );
+                      }
+                      else{
+                        return const CircularProgressIndicator();
+                      }
+                    }
+                ),
+              ],
             ),
-          ],
-        ),
-      ),
-      bottomNavigationBar: Row(
-        mainAxisAlignment: MainAxisAlignment.spaceBetween,
-        children: [
-          FloatingActionButton.extended(
-            heroTag: null,
-            tooltip: 'Reset all data',
-            icon: const Icon(Icons.cancel),
-            label: const Text('Reset all'),
-            onPressed: () {
-              //events.reset();  //TODO: remove before release!
-              configuration.reset();  //TODO: remove before release this is not a real use case!
-            },
           ),
-          FloatingActionButton.extended(
-            heroTag: null,
-            tooltip: 'Select Collection and download corresponding devices',
-            icon: const Icon(Icons.save),
-            label: const Text('Store'),
-            onPressed: () {
-              futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function
-                  debugPrint("Login credentials correct! Auth Token: " + value);
-
-                futureDevices.then((value) {
-                    debugPrint("Device List complete");
-                    configuration.devices = value;
-
-                  futureEventTypes.then((value) {
-                      debugPrint("Event Types List complete");
-                      configuration.eventTypes = value;
-
-                    debugPrint("EventType Json: " + jsonEncode(
-                        configuration.eventTypes[0]));
-                    debugPrint("Device Json: " + jsonEncode(
-                        configuration.devices[0]));
-                    debugPrint("Current Collection Json: " + jsonEncode(
-                        configuration.currentCollection));
-                    debugPrint("Sensor Login Json: " + jsonEncode(
-                        configuration.loginInformation));
-
-                    try {
-                      //Update id and urn for the add event widget with some initial data
-                      events.currentEvent.id = configuration.devices[0]
-                          .id; //TODO: fix if devices are an empty list.
-                      events.currentEvent.urn = configuration.devices[0].urn;
-                      events.currentEvent.description = '';
-                      events.currentEvent.label = '';
-                      events.currentEvent.type = configuration.eventTypes[0]
-                          .name;
-
-                      var date = DateTime.now().toUtc();
-                      var isoDate = date.toIso8601String();
-                      events.currentEvent.startDate = isoDate;
-                      events.currentEvent.endDate = isoDate;
-                      configuration.initialized = true;
-
-                      HapticFeedback.vibrate();
-                      //TODO: display success user feedback
-                    } catch (e) {
-                      throw Exception('Something went wrong try again');
-                    }
+        ),
+        bottomNavigationBar: Container(
+          margin: const EdgeInsets.symmetric(vertical: 10.0),
+          child: Row(
+            mainAxisAlignment: MainAxisAlignment.end,
+            children: [
+              const SizedBox(width: 10.0),
+              FloatingActionButton.extended(
+                heroTag: null,
+                tooltip: 'Reset all data',
+                icon: const Icon(Icons.cancel),
+                label: const Text('Reset all'),
+                onPressed: () {
+                  //events.reset();  //TODO: remove before release!
+                  configuration.reset();  //TODO: remove before release this is not a real use case!
+                },
+              ),
+              const SizedBox(width: 50),
+              FloatingActionButton.extended(
+                heroTag: null,
+                tooltip: 'Select Collection and download corresponding devices',
+                icon: const Icon(Icons.save),
+                label: const Text('Store'),
+                onPressed: () {
+                  futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function
+                    debugPrint("Login credentials correct! Auth Token: " + value);
+
+                    futureDevices.then((value) {
+                      debugPrint("Device List complete");
+                      configuration.devices = value;
+
+                      futureEventTypes.then((value) {
+                        debugPrint("Event Types List complete");
+                        configuration.eventTypes = value;
+
+                        debugPrint("EventType Json: " + jsonEncode(
+                            configuration.eventTypes[0]));
+                        debugPrint("Device Json: " + jsonEncode(
+                            configuration.devices[0]));
+                        debugPrint("Current Collection Json: " + jsonEncode(
+                            configuration.currentCollection));
+                        debugPrint("Sensor Login Json: " + jsonEncode(
+                            configuration.loginInformation));
+
+                        try {
+                          //Update id and urn for the add event widget with some initial data
+                          events.currentEvent.id = configuration.devices[0]
+                              .id; //TODO: fix if devices are an empty list.
+                          events.currentEvent.urn = configuration.devices[0].urn;
+                          events.currentEvent.description = '';
+                          events.currentEvent.label = '';
+                          events.currentEvent.type = configuration.eventTypes[0]
+                              .name;
+
+                          var date = DateTime.now().toUtc();
+                          var isoDate = date.toIso8601String();
+                          events.currentEvent.startDate = isoDate;
+                          events.currentEvent.endDate = isoDate;
+                          configuration.initialized = true;
+
+                          HapticFeedback.vibrate();
+                          //TODO: display success user feedback
+                        } catch (e) {
+                          throw Exception('Something went wrong try again');
+                        }
+                      });
+                    });
                   });
-                });
-              });
-              //TODO: display failed as user feedback somehow
-            },
+                  //TODO: display failed as user feedback somehow
+                },
+              ),
+              const SizedBox(width: 10.0),
+            ],
           ),
-        ],
-      ),
+        )
     );
   }
 }
diff --git a/lib/viewevents.dart b/lib/viewevents.dart
index a773fc1..6943a4d 100644
--- a/lib/viewevents.dart
+++ b/lib/viewevents.dart
@@ -246,7 +246,7 @@ class _ViewEvents extends State<ViewEvents> {
               },
             ),
           ),
-          const SizedBox(width: 10.0),
+          const SizedBox(width: 5.0),
         ],
       ),
     );
-- 
GitLab