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

cleanup

parent 63223af3
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,10 @@ class _MyHomePageState extends State<Configuration> {
final File file = File(filepath);
await file.writeAsString(eventsJson);
debugPrint('Stored file at: ' + filepath);
_status = 'Event database dump created: ' + filepath;
_statusStyle = const TextStyle(color: Colors.green);
setState(() {});
HapticFeedback.vibrate();
}
}
......@@ -84,15 +88,15 @@ class _MyHomePageState extends State<Configuration> {
await configuration.storeToSharedPrefs();
debugPrint('Configuration stored!');
_status = 'Login success & configuration stored';
_status = 'Login success, got all EventTypes, loaded Collection Devices & stored configuration for offline usage.';
_statusStyle = const TextStyle(color: Colors.green);
setState(() {});
} catch (e) {
debugPrint('Exception: $e');
_status = '$e';
String errorText = e.toString();
errorText = errorText.substring(10, errorText.length); //Remove 'Exception' from string.
_status = errorText;
_statusStyle = const TextStyle(color: Colors.red);
setState(() {});
}
}
......@@ -102,8 +106,9 @@ class _MyHomePageState extends State<Configuration> {
futureCollections = connector.fetchCollections();
await futureCollections; //wait and catch error here!
}catch(e){
debugPrint(e.toString());
_status = '$e';
String errorText = e.toString();
errorText = errorText.substring(10, errorText.length); //Remove 'Exception' from string.
_status = errorText;
_statusStyle = const TextStyle(color: Colors.red);
setState(() {});
}
......@@ -124,107 +129,106 @@ class _MyHomePageState extends State<Configuration> {
appBar: AppBar(
title: const Text('Configuration'),
),
body: SingleChildScrollView(
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 5.0),
child:
Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
const SizedBox(height: 50),
const Text(
'You must be online to do something here!',
style: TextStyle(fontSize: 14)
body: Container(
//constraints: const BoxConstraints.expand(),
margin: const EdgeInsets.symmetric(horizontal: 5.0),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
const SizedBox(height: 50),
const Text(
'You must be online to do something here!',
style: TextStyle(fontSize: 14)
),
const SizedBox(height: 50),
TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
initialValue: configuration.loginInformation.mail,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'E-Mail',
hintText: '',
),
const SizedBox(height: 50),
TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
initialValue: configuration.loginInformation.mail,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'E-Mail',
hintText: '',
),
onChanged: (value) {
configuration.loginInformation.mail = value;
},
onChanged: (value) {
configuration.loginInformation.mail = value;
},
),
const SizedBox(height: 15.0),
TextFormField(
obscureText: true,
autofocus: false,
initialValue: configuration.loginInformation.password,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
hintText: '',
),
const SizedBox(height: 15.0),
TextFormField(
obscureText: true,
autofocus: false,
initialValue: configuration.loginInformation.password,
decoration: const InputDecoration(
border: OutlineInputBorder(),
labelText: 'Password',
hintText: '',
),
onChanged: (value){
configuration.loginInformation.password = value;
},
),
const SizedBox(height: 50),
FutureBuilder<List<Collection>>(
future: futureCollections,
builder: (context, snapshot){
if (snapshot.hasData)
{
configuration.collections = [];
snapshot.data?.forEach((element) {
configuration.collections.add(element);
});
/*Initialize active collection with first received collection if not initialized yet*/
if(configuration.currentCollection.id == -1){
configuration.currentCollection = configuration.collections[0];
}
onChanged: (value){
configuration.loginInformation.password = value;
},
),
const SizedBox(height: 50),
FutureBuilder<List<Collection>>(
future: futureCollections,
builder: (context, snapshot){
if (snapshot.hasData)
{
configuration.collections = [];
snapshot.data?.forEach((element) {
configuration.collections.add(element);
});
return DropdownButtonFormField(
value: configuration.currentCollection.collectionName,
decoration: const InputDecoration(
labelText: 'Chose Collection',
border: OutlineInputBorder(),
),
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);
}
);
}
if (snapshot.hasError) {
debugPrint('Some error happened');
return const CircularProgressIndicator();
}
else{
return const CircularProgressIndicator();
/*Initialize active collection with first received collection if not initialized yet*/
if(configuration.currentCollection.id == -1){
configuration.currentCollection = configuration.collections[0];
}
return DropdownButtonFormField(
value: configuration.currentCollection.collectionName,
decoration: const InputDecoration(
labelText: 'Chose Collection',
border: OutlineInputBorder(),
),
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);
}
);
}
if (snapshot.hasError) {
debugPrint('Some error happened');
return const CircularProgressIndicator();
}
else{
return const CircularProgressIndicator();
}
}
),
const SizedBox(height: 50.0),
TextFormField(
minLines: 1,
maxLines: 5,
readOnly: true,
autofocus: false,
enabled: false,
style: _statusStyle,
controller: TextEditingController(
text: _status,
),
const SizedBox(height: 50.0),
TextFormField(
readOnly: true,
autofocus: false,
enabled: false,
style: _statusStyle,
controller: TextEditingController(
text: _status,
),
),
const SizedBox(height: 15.0),
],
),
),
],
),
),
),
......
......@@ -144,7 +144,7 @@ class SensorConnector {
if (response.statusCode == 201) {
return true;
} else if (response.statusCode == 401) {
throw Exception('No editor for UrnId ' + event.urnId.toString());
throw Exception('No write access for UrnId: ' + event.urnId.toString());
}
else {
debugPrint(response.statusCode.toString());
......
......@@ -72,8 +72,9 @@ class _ViewEvents extends State<ViewEvents> {
_status = 'export success';
_statusStyle = const TextStyle(color: Colors.green);
} catch (e) {
debugPrint('Exception: $e');
_status = '$e';
String errorText = e.toString();
errorText = errorText.substring(10, errorText.length); //Remove 'Exception' from string.
_status = errorText;
_statusStyle = const TextStyle(color: Colors.red);
setState(() {});
}
......
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