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

some ui improvements

parent 02b8797e
No related branches found
No related tags found
No related merge requests found
...@@ -44,160 +44,170 @@ class _MyHomePageState extends State<Configuration> { ...@@ -44,160 +44,170 @@ class _MyHomePageState extends State<Configuration> {
final EventStoreInstance events = EventStoreInstance(); final EventStoreInstance events = EventStoreInstance();
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text('Configuration'), title: const Text('Configuration'),
), ),
body: Center( body: Container(
child: Column( margin: const EdgeInsets.symmetric(horizontal: 5.0),
mainAxisAlignment: MainAxisAlignment.center, child:
children: <Widget>[ Center(
const Text( child: Column(
'You must be online to do something here!', mainAxisAlignment: MainAxisAlignment.center,
style: TextStyle(fontSize: 14) children: <Widget>[
), const Text(
const SizedBox(height: 50), 'You must be online to do something here!',
TextFormField( style: TextStyle(fontSize: 14)
keyboardType: TextInputType.emailAddress, ),
autofocus: false, const SizedBox(height: 50),
initialValue: configuration.loginInformation.mail, TextFormField(
decoration: const InputDecoration( keyboardType: TextInputType.emailAddress,
labelText: 'Sensor E-Mail', autofocus: false,
hintText: 'User for writing events', initialValue: configuration.loginInformation.mail,
), decoration: const InputDecoration(
onChanged: (value) { labelText: 'Sensor E-Mail',
configuration.loginInformation.mail = value; hintText: 'User for writing events',
}, ),
onFieldSubmitted: (value) { onChanged: (value) {
futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); configuration.loginInformation.mail = value;
}, },
), onFieldSubmitted: (value) {
TextFormField( futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
autofocus: false, },
initialValue: configuration.loginInformation.password, ),
decoration: const InputDecoration( TextFormField(
labelText: 'Sensor Password', autofocus: false,
hintText: 'Password for writing events', initialValue: configuration.loginInformation.password,
), decoration: const InputDecoration(
onChanged: (value){ labelText: 'Sensor Password',
configuration.loginInformation.password = value; hintText: 'Password for writing events',
}, ),
onFieldSubmitted: (value) { onChanged: (value){
futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password); configuration.loginInformation.password = value;
}, },
), onFieldSubmitted: (value) {
const SizedBox(height: 50), futureAuthToken = connector.getAuthToken(configuration.loginInformation.mail, configuration.loginInformation.password);
FutureBuilder<List<Collection>>( },
future: futureCollections, ),
builder: (context, snapshot){ const SizedBox(height: 50),
if (snapshot.hasData) FutureBuilder<List<Collection>>(
{ future: futureCollections,
configuration.collections = []; builder: (context, snapshot){
snapshot.data?.forEach((element) { if (snapshot.hasData)
configuration.collections.add(element); {
}); configuration.collections = [];
snapshot.data?.forEach((element) {
/*Initialize active collection with first received configuration.collections.add(element);
});
/*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);
}
return DropdownButtonFormField(
value: configuration.currentCollection.collectionName,
decoration: const InputDecoration(
labelText: 'Chose Collection',
),
items:
configuration.collections.map((Collection collection) {
return DropdownMenuItem(
value: collection.collectionName,
child: Text(collection.collectionName),
);
}).toList(),
onChanged: (value) {
configuration.currentCollection = configuration.getCollectionFromName(value.toString());
//Fetch new selected collection devices
futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id); futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
} }
);
} return DropdownButtonFormField(
else{ value: configuration.currentCollection.collectionName,
return const CircularProgressIndicator(); decoration: const InputDecoration(
} labelText: 'Chose Collection',
} ),
items:
configuration.collections.map((Collection collection) {
return DropdownMenuItem(
value: collection.collectionName,
child: Text(collection.collectionName),
);
}).toList(),
onChanged: (value) {
configuration.currentCollection = configuration.getCollectionFromName(value.toString());
//Fetch new selected collection devices
futureDevices = connector.fetchCollectionDevices(configuration.currentCollection.id);
}
);
}
else{
return const CircularProgressIndicator();
}
}
),
],
), ),
],
),
),
bottomNavigationBar: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
FloatingActionButton.extended(
heroTag: null,
tooltip: 'Reset all data',
icon: const Icon(Icons.cancel),
label: const Text('Reset all'),
onPressed: () {
//events.reset(); //TODO: remove before release!
configuration.reset(); //TODO: remove before release this is not a real use case!
},
), ),
FloatingActionButton.extended( ),
heroTag: null, bottomNavigationBar: Container(
tooltip: 'Select Collection and download corresponding devices', margin: const EdgeInsets.symmetric(vertical: 10.0),
icon: const Icon(Icons.save), child: Row(
label: const Text('Store'), mainAxisAlignment: MainAxisAlignment.end,
onPressed: () { children: [
futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function const SizedBox(width: 10.0),
debugPrint("Login credentials correct! Auth Token: " + value); FloatingActionButton.extended(
heroTag: null,
futureDevices.then((value) { tooltip: 'Reset all data',
debugPrint("Device List complete"); icon: const Icon(Icons.cancel),
configuration.devices = value; label: const Text('Reset all'),
onPressed: () {
futureEventTypes.then((value) { //events.reset(); //TODO: remove before release!
debugPrint("Event Types List complete"); configuration.reset(); //TODO: remove before release this is not a real use case!
configuration.eventTypes = value; },
),
debugPrint("EventType Json: " + jsonEncode( const SizedBox(width: 50),
configuration.eventTypes[0])); FloatingActionButton.extended(
debugPrint("Device Json: " + jsonEncode( heroTag: null,
configuration.devices[0])); tooltip: 'Select Collection and download corresponding devices',
debugPrint("Current Collection Json: " + jsonEncode( icon: const Icon(Icons.save),
configuration.currentCollection)); label: const Text('Store'),
debugPrint("Sensor Login Json: " + jsonEncode( onPressed: () {
configuration.loginInformation)); futureAuthToken.then((value){ //NOTE: Counterintuitive async callback function
debugPrint("Login credentials correct! Auth Token: " + value);
try {
//Update id and urn for the add event widget with some initial data futureDevices.then((value) {
events.currentEvent.id = configuration.devices[0] debugPrint("Device List complete");
.id; //TODO: fix if devices are an empty list. configuration.devices = value;
events.currentEvent.urn = configuration.devices[0].urn;
events.currentEvent.description = ''; futureEventTypes.then((value) {
events.currentEvent.label = ''; debugPrint("Event Types List complete");
events.currentEvent.type = configuration.eventTypes[0] configuration.eventTypes = value;
.name;
debugPrint("EventType Json: " + jsonEncode(
var date = DateTime.now().toUtc(); configuration.eventTypes[0]));
var isoDate = date.toIso8601String(); debugPrint("Device Json: " + jsonEncode(
events.currentEvent.startDate = isoDate; configuration.devices[0]));
events.currentEvent.endDate = isoDate; debugPrint("Current Collection Json: " + jsonEncode(
configuration.initialized = true; configuration.currentCollection));
debugPrint("Sensor Login Json: " + jsonEncode(
HapticFeedback.vibrate(); configuration.loginInformation));
//TODO: display success user feedback
} catch (e) { try {
throw Exception('Something went wrong try again'); //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 isoDate = date.toIso8601String();
events.currentEvent.startDate = isoDate;
events.currentEvent.endDate = isoDate;
configuration.initialized = true;
HapticFeedback.vibrate();
//TODO: display success user feedback
} catch (e) {
throw Exception('Something went wrong try again');
}
});
});
}); });
}); //TODO: display failed as user feedback somehow
}); },
//TODO: display failed as user feedback somehow ),
}, const SizedBox(width: 10.0),
],
), ),
], )
),
); );
} }
} }
...@@ -246,7 +246,7 @@ class _ViewEvents extends State<ViewEvents> { ...@@ -246,7 +246,7 @@ class _ViewEvents extends State<ViewEvents> {
}, },
), ),
), ),
const SizedBox(width: 10.0), const SizedBox(width: 5.0),
], ],
), ),
); );
......
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