diff --git a/lib/configuration.dart b/lib/configuration.dart index 3cb42ee2dc1198bded33711e8d82735e1758c108..f47d5f5ae837153f7a0e77388a5c6cc6483693a8 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -1,12 +1,9 @@ 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'; import 'sensorconnector.dart'; - class Configuration extends StatefulWidget { const Configuration({Key? key}) : super(key: key); @@ -31,7 +28,9 @@ class _MyHomePageState extends State<Configuration> { //Start fetching all possible sensor data as soon as possible: futureCollections = connector.fetchCollections(); futureEventTypes = connector.fetchEventTypes(); - futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); + if (configuration.currentCollection.id != -1) { + futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); + } futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); } late Future<String> eventTypes; @@ -99,6 +98,7 @@ class _MyHomePageState extends State<Configuration> { collection if not initialized yet*/ if(configuration.currentCollection.id == -1){ configuration.currentCollection = configuration.collections[0]; + futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); } return DropdownButtonFormField( @@ -142,7 +142,6 @@ class _MyHomePageState extends State<Configuration> { }, ), FloatingActionButton.extended( - heroTag: null, tooltip: 'Select Collection and download corresponding devices', icon: const Icon(Icons.save), @@ -153,29 +152,31 @@ class _MyHomePageState extends State<Configuration> { //Update configuration with newly fetched data futureDevices.then((value) => configuration.devices = value); futureEventTypes.then((value) => configuration.eventTypes = value); - - //Update id and urn for the add event widget with some initial data - events.currentEvent.id = configuration.devices[0].id; - 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 isodata = date.toIso8601String(); - events.currentEvent.startDate = isodata; - events.currentEvent.endDate = isodata; - configuration.initialized = true; - - HapticFeedback.vibrate(); + print("Devices: " + configuration.devices.toString()); //Still empty on first execution Why? + // TODO: Move fetchCollectionDevices to an own future and set configuration inside on finish! + 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 isodata = date.toIso8601String(); + events.currentEvent.startDate = isodata; + events.currentEvent.endDate = isodata; + configuration.initialized = true; + + HapticFeedback.vibrate(); + //TODO: display success + } catch(e){ + throw Exception('Something went wrong try again'); + } }); }); - - //login(); - //fetchEventTypes(); - //updateDevices(configuration.currentCollection.id); - //HapticFeedback.vibrate(); + //TODO: display failed here somehow }, ), ], diff --git a/lib/datamodel.dart b/lib/datamodel.dart index 4d16b19db7fa64ea2a9cd47c8458e49cc7fe457b..d81ac2e1ffba70f010e4a3ae9d9e1953c26a33ac 100644 --- a/lib/datamodel.dart +++ b/lib/datamodel.dart @@ -1,7 +1,3 @@ -import 'dart:convert'; - -import 'package:shared_preferences/shared_preferences.dart'; - class Collection { int id; diff --git a/lib/main.dart b/lib/main.dart index 729c29c6666b33105266414332550953caaf29c7..00c8edfed35d4f24d73e3768f0d63226e06ca518 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,4 @@ import 'package:flutter/material.dart'; - import 'datamodel.dart'; import 'addevent.dart'; import 'viewevents.dart'; diff --git a/lib/overview.dart b/lib/overview.dart index 5f819aa4539ab17e46ec641b30ee7038f6bef612..b505824330f1e0442efb247b521a0b07a6636344 100644 --- a/lib/overview.dart +++ b/lib/overview.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; class Overview extends StatelessWidget { diff --git a/lib/viewevents.dart b/lib/viewevents.dart index a18144ff95d0bfc109acdb7fcd790f6db0277866..748f775d94bad668035da3959edd5642e085b275 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -1,6 +1,4 @@ import 'dart:convert'; - -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'datamodel.dart'; import 'package:http/http.dart' as http; @@ -318,11 +316,6 @@ class _ViewEvents extends State<ViewEvents> { ], ); } - - - } - - //TODO: allow editing fields here. Check validation of input value! \ No newline at end of file