diff --git a/lib/configuration.dart b/lib/configuration.dart index 8c95d9094b96536b24446f4cb22c2f8dfa36e8b9..927a87ef47d6f2d97e00d0685bde2378cb2c7bde 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -58,8 +58,8 @@ class _MyHomePageState extends State<Configuration> { try{ token = await connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); - configuration.devices = await futureDevices; //already fetched just use the data. - configuration.eventTypes = await futureEventTypes; //already fetched just use the data. + configuration.devices = await connector.fetchCollectionDevices(configuration.currentCollection.id); //await futureDevices; //already fetched just use the data. + configuration.eventTypes = await connector.fetchEventTypes(); event.currentEvent.id = 0; event.currentEvent.urnId = configuration.devices[0].id; //TODO: fix if devices are an empty list. @@ -68,7 +68,6 @@ class _MyHomePageState extends State<Configuration> { event.currentEvent.label = ''; event.currentEvent.type = configuration.eventTypes[0].name; - var date = DateTime.now().toUtc(); var isoDate = date.toIso8601String(); event.currentEvent.startDate = isoDate; @@ -94,20 +93,13 @@ class _MyHomePageState extends State<Configuration> { } Future<void> fetchInitData() async { - try { - //Start fetching all possible sensor data as soon as possible: futureCollections = connector.fetchCollections(); - futureEventTypes = connector.fetchEventTypes(); - if (configuration.currentCollection.id != -1) { - futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); - } - - await futureCollections; - await futureEventTypes; - await futureDevices; + await futureCollections; //wait and catch error here! }catch(e){ debugPrint(e.toString()); + _status = '$e'; + setState(() {}); } } @@ -116,7 +108,6 @@ class _MyHomePageState extends State<Configuration> { super.initState(); fetchInitData(); } - late Future<String> eventTypes; @override Widget build(BuildContext context) { @@ -153,9 +144,6 @@ class _MyHomePageState extends State<Configuration> { onChanged: (value) { configuration.loginInformation.mail = value; }, - onFieldSubmitted: (value) { - //futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); - }, ), const SizedBox(height: 15.0), TextFormField( @@ -170,9 +158,6 @@ class _MyHomePageState extends State<Configuration> { onChanged: (value){ configuration.loginInformation.password = value; }, - onFieldSubmitted: (value) { - //futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); - }, ), const SizedBox(height: 50), FutureBuilder<List<Collection>>( @@ -185,12 +170,9 @@ class _MyHomePageState extends State<Configuration> { configuration.collections.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(configuration.currentCollection.id == -1){ configuration.currentCollection = configuration.collections[0]; - futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); - //TODO: shall this be removed here and just done at confirmation.? } return DropdownButtonFormField( @@ -213,6 +195,10 @@ class _MyHomePageState extends State<Configuration> { } ); } + if (snapshot.hasError) { + debugPrint('Some error happened'); + return const CircularProgressIndicator(); + } else{ return const CircularProgressIndicator(); }