From 2b703d7c8a38baa317246441b3ab0b65b645f5a2 Mon Sep 17 00:00:00 2001
From: Maximilian Betz <Maximilian.Betz@awi.de>
Date: Tue, 1 Mar 2022 12:27:29 +0100
Subject: [PATCH] some cleanup

---
 lib/configuration.dart | 28 ++++++++++++----------------
 lib/main.dart          |  8 ++++----
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/lib/configuration.dart b/lib/configuration.dart
index a0cf374..275112a 100644
--- a/lib/configuration.dart
+++ b/lib/configuration.dart
@@ -1,5 +1,6 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
 import 'package:http/http.dart' as http;
 import 'dart:convert';
 import 'datamodel.dart';
@@ -11,16 +12,12 @@ Future<List<Device>> updateDevices(int collectionId) async {
   // Get Access to local device and current event store.
   DeviceStoreInstance availableDevices = DeviceStoreInstance();
   EventCurrentInstance currentEvent = EventCurrentInstance();
+  List<Device> collectionDevices = [];
 
   final response = await http
       .get(Uri.parse(url));
 
-  debugPrint("Got something via Sensor Rest...");
-
-  List<Device> collectionDevices = [];
-
   if (response.statusCode == 200) {
-    // If the server did return a 200 OK response, then parse the JSON.
     List<dynamic> data = json.decode(response.body);
     for (var entry in data) {
       collectionDevices.add(Device.fromJson(entry));
@@ -31,16 +28,14 @@ Future<List<Device>> updateDevices(int collectionId) async {
       debugPrint(device.toString());
     }
 
-    /*Update to local event store*/
+    /*Update to local device store*/
     availableDevices.store = collectionDevices;
-    //Update id and urn in add event widget
+    //Update id and urn for the add event widget
     currentEvent.store.id = collectionDevices[0].id;
     currentEvent.store.urn = collectionDevices[0].urn;
 
     return collectionDevices;
   } else {
-    // If the server did not return a 200 OK response,
-    // then throw an exception.
     throw Exception('Failed to load Collection');
   }
 }
@@ -57,9 +52,6 @@ Future<List<Collection>> fetchCollections() async {
         .toList();
 
   } else {
-    // If the server did not return a 200 OK response,
-    // then throw an exception.
-    //throw Exception('Failed to load Collection');
     debugPrint('Failed to load Collection');
     return collectionList;
   }
@@ -100,20 +92,23 @@ class _MyHomePageState extends State<Configuration> {
         child: Column(
           mainAxisAlignment: MainAxisAlignment.center,
           children: <Widget>[
+            const Text(
+                'You must be online to do something here!',
+                style: TextStyle(fontSize: 18)
+            ),
+            const SizedBox(height: 50),
             FutureBuilder<List<Collection>>(
                 future: futureCollections,
                 builder: (context, snapshot){
                   if (snapshot.hasData)
                   {
                     collections.store = [];
-
-                    //debugPrint('Got Collections:');
                     snapshot.data?.forEach((element) {
-                      //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*/
+                    /*Initialize active collection with first received
+                    collection if not initialized yet*/
                     if(activeCollection.store.collectionName == ''){
                       activeCollection.store = collections.store[0];
                     }
@@ -161,6 +156,7 @@ class _MyHomePageState extends State<Configuration> {
             label: const Text('Select'),
             onPressed: () {
               updateDevices(activeCollection.store.id);
+              HapticFeedback.vibrate();
             },
           ),
         ],
diff --git a/lib/main.dart b/lib/main.dart
index df29534..720fa4f 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -36,7 +36,7 @@ void main() {
   currentEvent.store.label = 'PS129_ABC';
   currentEvent.store.type = 'Deployment';
   
-  //Add some dummy events to eventstore. Just development purpose. TODO: Remove after development.
+  //Add some dummy events to event store. Just development purpose. TODO: Remove after development.
   events.store.add(Event.fromJson({
     'id': 8311,
     'urn': 'station:neumayer_iii:awi_snow_sampler_1',
@@ -87,9 +87,9 @@ void main() {
     initialRoute: '/',
     routes: {
       '/': (context) => Overview(),
-      '/second': (context) => AddEvent(),
-      '/third': (context) => ViewEvents(),
-      '/forth': (context) => Configuration(),
+      '/second': (context) => const AddEvent(),
+      '/third': (context) => const ViewEvents(),
+      '/forth': (context) => const Configuration(),
     },
   ));
 }
-- 
GitLab