From 073161a2913430e1963c9b568826f2c83271ff11 Mon Sep 17 00:00:00 2001
From: Maximilian Betz <Maximilian.Betz@awi.de>
Date: Wed, 19 Jan 2022 14:38:43 +0100
Subject: [PATCH] separated each page into an own .dart file

---
 lib/addevent.dart                       |  98 +++++++
 lib/configuration.dart                  | 118 ++++++++
 lib/{data_model.dart => datamodel.dart} |  49 +++-
 lib/main.dart                           | 357 ++----------------------
 lib/overview.dart                       |  35 +++
 lib/viewevents.dart                     | 104 +++++++
 6 files changed, 408 insertions(+), 353 deletions(-)
 create mode 100644 lib/addevent.dart
 create mode 100644 lib/configuration.dart
 rename lib/{data_model.dart => datamodel.dart} (52%)
 create mode 100644 lib/overview.dart
 create mode 100644 lib/viewevents.dart

diff --git a/lib/addevent.dart b/lib/addevent.dart
new file mode 100644
index 0000000..8264b1d
--- /dev/null
+++ b/lib/addevent.dart
@@ -0,0 +1,98 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'datamodel.dart';
+
+class AddEvent extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    final EventTypeStoreInstance eventTypes = EventTypeStoreInstance();
+
+    return Scaffold(
+      appBar: AppBar(title: const Text("Add Event")),
+      body:
+      Column(
+          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
+          children: <Widget>[
+            TextFormField(
+              decoration: const InputDecoration(
+                  labelText: 'Label'
+              ),
+            ),
+            DropdownButtonFormField(
+                decoration: const InputDecoration(
+                  labelText: 'Event Type',
+                ),
+                items: [
+                  DropdownMenuItem(
+                    child: Text('Calibration'),
+                    value: 'Calibration',
+                  ),
+                  DropdownMenuItem(
+                    child: Text('Information'),
+                    value: 'Information',
+                  )
+                ],
+                onChanged: (value) {
+
+                }
+            ),
+            DropdownButtonFormField(
+                decoration: const InputDecoration(
+                  labelText: 'URN',
+                ),
+                items: [
+                  DropdownMenuItem(
+                    child: Text('ADCP'),
+                    value: 'ADCP',
+                  ),
+                  DropdownMenuItem(
+                    child: Text('EM712'),
+                    value: 'EM712',
+                  )
+                ],
+                onChanged: (value) {
+                }
+            ),
+            TextFormField(
+              decoration: const InputDecoration(
+                  labelText: 'Description'
+              ),
+            ),
+            TextFormField(
+              decoration: const InputDecoration(
+                  labelText: 'Latitude'
+              ),
+            ),
+            TextFormField(
+              decoration: const InputDecoration(
+                  labelText: 'Longitude'
+              ),
+            ),
+            TextFormField(
+              decoration: const InputDecoration(
+                  labelText: 'Elevation'
+              ),
+            )
+          ]),
+      bottomNavigationBar: Row(
+        mainAxisAlignment: MainAxisAlignment.end,
+        children: const [
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: null,
+            tooltip: 'Get GNSS from device',
+            child: Icon(Icons.my_location),
+          ),
+          SizedBox(width: 50),
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: null,
+            tooltip: 'Add Event',
+            child: Icon(Icons.add),
+          ),
+          SizedBox(width: 20),
+        ],
+      ),
+    );
+  }
+}
diff --git a/lib/configuration.dart b/lib/configuration.dart
new file mode 100644
index 0000000..15106e3
--- /dev/null
+++ b/lib/configuration.dart
@@ -0,0 +1,118 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+
+
+class Configuration extends StatefulWidget {
+  @override
+  State<Configuration> createState() => _MyHomePageState();
+}
+
+class _MyHomePageState extends State<Configuration> {
+  int _counter = 0;
+  int _factor = 1;
+
+  String selectedValue = '1';
+  var available_items = [
+    '1',
+    '10',
+    '100',
+  ];
+
+  late Future<String> eventTypes;
+
+  @override
+  void initState() {
+    super.initState();
+  }
+
+  void _incrementCounter() {
+    setState(() {
+      _counter = _counter + _factor;
+    });
+  }
+
+  void _decrementCounter() {
+    setState(() {
+      _counter = _counter - _factor;
+    });
+  }
+
+  void _resetCounter() {
+    setState(() {
+      _counter = 0;
+    });
+  }
+
+  void _getCollections() {
+    setState(() {});
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(
+        title: Text('Configuration'),
+      ),
+      body: Center(
+        child: Column(
+          mainAxisAlignment: MainAxisAlignment.center,
+          children: <Widget>[
+            const Text(
+              'You have pushed the button this many times:',
+            ),
+            Text(
+              '$_counter',
+              style: Theme.of(context).textTheme.headline2,
+            ),
+            DropdownButton(
+              value: selectedValue,
+              icon: const Icon(Icons.keyboard_arrow_down),
+              items: available_items.map((String available_items) {
+                return DropdownMenuItem(
+                  value: available_items,
+                  child: Text(available_items),
+                );
+              }).toList(),
+              onChanged: (String? newValue) {
+                setState(() {
+                  selectedValue = newValue!;
+                  _factor = int.parse(selectedValue);
+                });
+              },
+            ),
+            Text('blabla'),
+          ],
+        ),
+      ),
+      bottomNavigationBar: Row(
+        mainAxisAlignment: MainAxisAlignment.spaceBetween,
+        children: [
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: _incrementCounter,
+            tooltip: 'Increment',
+            child: const Icon(Icons.add),
+          ),
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: _decrementCounter,
+            tooltip: 'Decrement',
+            child: const Text('-'),
+          ),
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: _resetCounter,
+            tooltip: 'Reset to 0',
+            child: const Icon(Icons.delete),
+          ),
+          FloatingActionButton(
+            heroTag: null,
+            onPressed: _getCollections,
+            tooltip: 'Reset to 0',
+            child: const Text('Update'),
+          ),
+        ],
+      ),
+    );
+  }
+}
diff --git a/lib/data_model.dart b/lib/datamodel.dart
similarity index 52%
rename from lib/data_model.dart
rename to lib/datamodel.dart
index 5c914b7..0896f73 100644
--- a/lib/data_model.dart
+++ b/lib/datamodel.dart
@@ -34,24 +34,49 @@ class Event{
 
 abstract class EventStoreBase{
   List<Event> store = [];
+}
+
 
-  //void setStore(List<Event> st){
-  //  store = st;
-  //}
 
-  //void reset(){
-  //  store = [];
-  //}
-}
 
 class EventType{
-  String name;
   int id;
+  String name;
+
+  EventType(
+    this.id,
+    this.name
+  );
+
+  factory EventType.fromJson(Map<String, dynamic> parsedJson){
+    return EventType(parsedJson['id'] as int, parsedJson['name'] as String);
+  }
+}
+
+abstract class EventTypeStoreBase{
+  List<EventType> store = [];
+}
+
+class EventStoreInstance extends EventStoreBase {
+  static final EventStoreInstance _instance = EventStoreInstance._internal();
+
+  factory EventStoreInstance() {
+    return _instance;
+  }
 
-  EventType({
-    required this.name,
-    required this.id
-});
+  EventStoreInstance._internal() {
+    store = [];
+  }
 }
 
+class EventTypeStoreInstance extends EventTypeStoreBase{
+  static final EventTypeStoreInstance _instance = EventTypeStoreInstance._internal();
 
+  factory EventTypeStoreInstance(){
+    return _instance;
+  }
+
+  EventTypeStoreInstance._internal(){
+    store = [];
+  }
+}
\ No newline at end of file
diff --git a/lib/main.dart b/lib/main.dart
index 82b6fa3..7277b4b 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -1,22 +1,20 @@
 import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
-import 'data_model.dart';
 
-class EventStoreInstance extends EventStoreBase {
-  static final EventStoreInstance _instance = EventStoreInstance._internal();
+import 'datamodel.dart';
+import 'addevent.dart';
+import 'viewevents.dart';
+import 'overview.dart';
+import 'configuration.dart';
 
-  factory EventStoreInstance() {
-    return _instance;
-  }
 
-  EventStoreInstance._internal() {
-    store = [];
-  }
-}
 
 void main() {
-  //Add some dummy events to eventstore
+  
   EventStoreInstance events = EventStoreInstance();
+  EventTypeStoreInstance eventTypes = EventTypeStoreInstance();
+
+  //Add some dummy events to eventstore
   events.store.add(Event.fromJson({
     'id': 8311,
     'urn': 'station:neumayer_iii:awi_snow_sampler_1',
@@ -49,6 +47,13 @@ void main() {
     'description': 'Remi tool Tag1 1 Traverse',
     'status': 'PENDING'
   }));
+  
+  //Add some dummy eventtypes.  TODO: request from https://sensor.awi.de/rest/sensors/events/getAllEventTypes
+  eventTypes.store.add(EventType.fromJson({'id': 317, 'name':'Configuration'}));
+  eventTypes.store.add(EventType.fromJson({'id': 216, 'name':'Decommissioned'}));
+  eventTypes.store.add(EventType.fromJson({'id': 187, 'name':'Deployment'}));
+  eventTypes.store.add(EventType.fromJson({'id': 50, 'name':'Information'}));
+  eventTypes.store.add(EventType.fromJson({'id': 16, 'name':'Maintenance'}));
 
   runApp(MaterialApp(
     title: 'Mobile Event Log',
@@ -65,337 +70,7 @@ void main() {
   ));
 }
 
-class Overview extends StatelessWidget {
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(title: const Text('Mobile Event Log')),
-      body: Center(
-          child: Column(
-        mainAxisAlignment: MainAxisAlignment.spaceAround,
-        children: <Widget>[
-          ElevatedButton(
-            child: const Text('Add Event'),
-            onPressed: () {
-              Navigator.pushNamed(context, '/second');
-            },
-          ),
-          ElevatedButton(
-            child: const Text('View Added Events'),
-            onPressed: () {
-              Navigator.pushNamed(context, '/third');
-            },
-          ),
-          ElevatedButton(
-            child: const Text('Configuration'),
-            onPressed: () {
-              Navigator.pushNamed(context, '/forth');
-            },
-          ),
-        ],
-      )),
-    );
-  }
-}
-
-class AddEvent extends StatelessWidget {
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(title: const Text("Add Event")),
-      body:
-          Column(
-              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
-              children: <Widget>[
-                TextFormField(
-                  decoration: InputDecoration(
-                      labelText: 'Label'
-                  ),
-                ),
-                DropdownButtonFormField(
-                    decoration: InputDecoration(
-                      labelText: 'Event Type',
-                    ),
-                    items: [
-                      DropdownMenuItem(
-                        child: Text('Calibration'),
-                        value: 'Calibration',
-                      ),
-                      DropdownMenuItem(
-                        child: Text('Information'),
-                        value: 'Information',
-                      )
-                    ],
-                    onChanged: (value) {
 
-                    }
-                ),
-                DropdownButtonFormField(
-                  decoration: InputDecoration(
-                    labelText: 'URN',
-                  ),
-                    items: [
-                      DropdownMenuItem(
-                          child: Text('ADCP'),
-                          value: 'ADCP',
-                      ),
-                      DropdownMenuItem(
-                          child: Text('EM712'),
-                          value: 'EM712',
-                      )
-                    ],
-                    onChanged: (value) {
 
-                    }
-                ),
-                TextFormField(
-                  decoration: InputDecoration(
-                      labelText: 'Description'
-                  ),
-                ),
-                TextFormField(
-                  decoration: InputDecoration(
-                      labelText: 'Latitude'
-                  ),
-                ),
-                TextFormField(
-                  decoration: InputDecoration(
-                      labelText: 'Longitude'
-                  ),
-                ),
-                TextFormField(
-                  decoration: InputDecoration(
-                      labelText: 'Elevation'
-                  ),
-                )
-              ]),
-      bottomNavigationBar: Row(
-        mainAxisAlignment: MainAxisAlignment.end,
-        children: const [
-          FloatingActionButton(
-            heroTag: null,
-            onPressed: null,
-            tooltip: 'Add Event locally',
-            child: Icon(Icons.add),
-          )
-        ],
-      ),
-    );
-  }
-}
 
-class ViewEvents extends StatelessWidget {
-  @override
-  Widget build(BuildContext context) {
-    // Get singleton to access locally stored events:
-    final EventStoreInstance events = EventStoreInstance();
-    return Scaffold(
-      appBar: AppBar(
-        title: const Text("View Added Events"),
-      ),
-      body: SingleChildScrollView(
-        scrollDirection: Axis.horizontal,
-        child: SingleChildScrollView(
-          scrollDirection: Axis.vertical,
-          child: DataTable(
-            columns: const <DataColumn>[
-              DataColumn(
-                label: Text(
-                  'Id',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-              DataColumn(
-                label: Text(
-                  'URN',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-              DataColumn(
-                label: Text(
-                  'Label',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-              DataColumn(
-                label: Text(
-                  'Type',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-              DataColumn(
-                label: Text(
-                  'Description',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-              DataColumn(
-                label: Text(
-                  'Status',
-                  style: TextStyle(fontStyle: FontStyle.italic),
-                ),
-              ),
-            ],
-            rows: <DataRow>[
-              for (var event in events.store)
-                DataRow(
-                  cells: <DataCell>[
-                    DataCell(Text(event.id.toString())),
-                    DataCell(Text(event.urn)),
-                    DataCell(
-                      TextFormField(
-                        initialValue: event.label,
-                        onFieldSubmitted: (val) {
-                          event.label = val; //Update Database
-                        },
-                      ),
-                    ),
-                    DataCell(Text(event.type)),
-                    DataCell(
-                      TextFormField(
-                        initialValue: event.description,
-                        onFieldSubmitted: (val) {
-                          event.description = val; //Update Database
-                        },
-                      ),
-                    ),
-                    DataCell(
-                      DropdownButtonFormField(
-                        //value: Text('abe'),
-                        items: <DropdownMenuItem>[
-                          DropdownMenuItem(
-                            child: Text('abs'),
-                            value: Text('1'),
-                          ),
-                          DropdownMenuItem(
-                            child: Text('abc'),
-                            value: Text('1'),
-                          ),
-                        ],
-                        onChanged: null,
-                      ),
-                    ),
-                  ],
-                ),
-            ],
-          ),
-        ),
-      ),
-    );
-  }
-}
-
-class Configuration extends StatefulWidget {
-  @override
-  State<Configuration> createState() => _MyHomePageState();
-}
 
-class _MyHomePageState extends State<Configuration> {
-  int _counter = 0;
-  int _factor = 1;
-
-  String selectedValue = '1';
-  var available_items = [
-    '1',
-    '10',
-    '100',
-  ];
-
-  late Future<String> eventTypes;
-
-  @override
-  void initState() {
-    super.initState();
-  }
-
-  void _incrementCounter() {
-    setState(() {
-      _counter = _counter + _factor;
-    });
-  }
-
-  void _decrementCounter() {
-    setState(() {
-      _counter = _counter - _factor;
-    });
-  }
-
-  void _resetCounter() {
-    setState(() {
-      _counter = 0;
-    });
-  }
-
-  void _getCollections() {
-    setState(() {});
-  }
-
-  @override
-  Widget build(BuildContext context) {
-    return Scaffold(
-      appBar: AppBar(
-        title: Text('Configuration'),
-      ),
-      body: Center(
-        child: Column(
-          mainAxisAlignment: MainAxisAlignment.center,
-          children: <Widget>[
-            const Text(
-              'You have pushed the button this many times:',
-            ),
-            Text(
-              '$_counter',
-              style: Theme.of(context).textTheme.headline2,
-            ),
-            DropdownButton(
-              value: selectedValue,
-              icon: const Icon(Icons.keyboard_arrow_down),
-              items: available_items.map((String available_items) {
-                return DropdownMenuItem(
-                  value: available_items,
-                  child: Text(available_items),
-                );
-              }).toList(),
-              onChanged: (String? newValue) {
-                setState(() {
-                  selectedValue = newValue!;
-                  _factor = int.parse(selectedValue);
-                });
-              },
-            ),
-            Text('blabla'),
-          ],
-        ),
-      ),
-      bottomNavigationBar: Row(
-        mainAxisAlignment: MainAxisAlignment.spaceBetween,
-        children: [
-          FloatingActionButton(
-            heroTag: null,
-            onPressed: _incrementCounter,
-            tooltip: 'Increment',
-            child: const Icon(Icons.add),
-          ),
-          FloatingActionButton(
-            heroTag: null,
-            onPressed: _decrementCounter,
-            tooltip: 'Decrement',
-            child: const Text('-'),
-          ),
-          FloatingActionButton(
-            heroTag: null,
-            onPressed: _resetCounter,
-            tooltip: 'Reset to 0',
-            child: const Icon(Icons.delete),
-          ),
-          FloatingActionButton(
-            heroTag: null,
-            onPressed: _getCollections,
-            tooltip: 'Reset to 0',
-            child: const Text('Update'),
-          ),
-        ],
-      ),
-    );
-  }
-}
diff --git a/lib/overview.dart b/lib/overview.dart
new file mode 100644
index 0000000..1eb727f
--- /dev/null
+++ b/lib/overview.dart
@@ -0,0 +1,35 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+
+class Overview extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    return Scaffold(
+      appBar: AppBar(title: const Text('Mobile Event Log')),
+      body: Center(
+          child: Column(
+            mainAxisAlignment: MainAxisAlignment.spaceAround,
+            children: <Widget>[
+              ElevatedButton(
+                child: const Text('Add Event'),
+                onPressed: () {
+                  Navigator.pushNamed(context, '/second');
+                },
+              ),
+              ElevatedButton(
+                child: const Text('View Added Events'),
+                onPressed: () {
+                  Navigator.pushNamed(context, '/third');
+                },
+              ),
+              ElevatedButton(
+                child: const Text('Configuration'),
+                onPressed: () {
+                  Navigator.pushNamed(context, '/forth');
+                },
+              ),
+            ],
+          )),
+    );
+  }
+}
\ No newline at end of file
diff --git a/lib/viewevents.dart b/lib/viewevents.dart
new file mode 100644
index 0000000..a4ab274
--- /dev/null
+++ b/lib/viewevents.dart
@@ -0,0 +1,104 @@
+import 'package:flutter/cupertino.dart';
+import 'package:flutter/material.dart';
+import 'datamodel.dart';
+
+class ViewEvents extends StatelessWidget {
+  @override
+  Widget build(BuildContext context) {
+    // Get singleton to access locally stored events:
+    final EventStoreInstance events = EventStoreInstance();
+    return Scaffold(
+      appBar: AppBar(
+        title: const Text("View Added Events"),
+      ),
+      body: SingleChildScrollView(
+        scrollDirection: Axis.horizontal,
+        child: SingleChildScrollView(
+          scrollDirection: Axis.vertical,
+          child: DataTable(
+            columns: const <DataColumn>[
+              DataColumn(
+                label: Text(
+                  'Id',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+              DataColumn(
+                label: Text(
+                  'URN',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+              DataColumn(
+                label: Text(
+                  'Label',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+              DataColumn(
+                label: Text(
+                  'Type',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+              DataColumn(
+                label: Text(
+                  'Description',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+              DataColumn(
+                label: Text(
+                  'Status',
+                  style: TextStyle(fontStyle: FontStyle.italic),
+                ),
+              ),
+            ],
+            rows: <DataRow>[
+              for (var event in events.store)
+                DataRow(
+                  cells: <DataCell>[
+                    DataCell(Text(event.id.toString())),
+                    DataCell(Text(event.urn)),
+                    DataCell(
+                      TextFormField(
+                        initialValue: event.label,
+                        onFieldSubmitted: (val) {
+                          event.label = val; //Update Database
+                        },
+                      ),
+                    ),
+                    DataCell(Text(event.type)),
+                    DataCell(
+                      TextFormField(
+                        initialValue: event.description,
+                        onFieldSubmitted: (val) {
+                          event.description = val; //Update Database
+                        },
+                      ),
+                    ),
+                    DataCell(
+                      DropdownButtonFormField(
+                        //value: Text('abe'),
+                        items: <DropdownMenuItem>[
+                          DropdownMenuItem(
+                            child: Text('abs'),
+                            value: Text('1'),
+                          ),
+                          DropdownMenuItem(
+                            child: Text('abc'),
+                            value: Text('1'),
+                          ),
+                        ],
+                        onChanged: null,
+                      ),
+                    ),
+                  ],
+                ),
+            ],
+          ),
+        ),
+      ),
+    );
+  }
+}
\ No newline at end of file
-- 
GitLab