diff --git a/lib/configuration.dart b/lib/configuration.dart index 8b9b93c57295fd676809aec2495af346ecef371a..5fda58ad2a2dfbd20d1fd17372d04a5d58f41ad4 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -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), - - ], - ), + ), + ], ), ), ), diff --git a/lib/sensorconnector.dart b/lib/sensorconnector.dart index fd798b117963566da37437c1f978c6a5bbb09248..b7846b75a6dacc1d49e54a83488955563763a51a 100644 --- a/lib/sensorconnector.dart +++ b/lib/sensorconnector.dart @@ -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()); diff --git a/lib/viewevents.dart b/lib/viewevents.dart index 18c8ea9c2d70f97494e2b070ee0151614c9d9f10..6d843b802597b9b117258e3475dd28e2c7e5dbe0 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -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(() {}); }