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

further improved exception handling and some cleanup

parent 30bca1b0
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
......
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