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