Skip to content
Snippets Groups Projects
Commit 2b703d7c authored by Maximilian Betz's avatar Maximilian Betz
Browse files

some cleanup

parent d9b87bbc
No related branches found
No related tags found
No related merge requests found
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();
},
),
],
......
......@@ -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(),
},
));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment