diff --git a/lib/configuration.dart b/lib/configuration.dart index 927a87ef47d6f2d97e00d0685bde2378cb2c7bde..9665dd862b5ef93aa73e9636c7c4857434247fcb 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -25,6 +25,7 @@ class _MyHomePageState extends State<Configuration> { SensorConnector connector = SensorConnector(); final ConfigurationStoreInstance configuration = ConfigurationStoreInstance(); String _status = ''; + TextStyle _statusStyle = const TextStyle(color: Colors.black); Future<void> dumpToFile() async{ var date = DateTime.now().toUtc(); @@ -48,6 +49,7 @@ class _MyHomePageState extends State<Configuration> { final File file = File(filepath); await file.writeAsString(eventsJson); debugPrint('Stored file at: ' + filepath); + HapticFeedback.vibrate(); } } @@ -83,11 +85,14 @@ class _MyHomePageState extends State<Configuration> { debugPrint('Configuration stored!'); _status = 'Login success & configuration stored'; + _statusStyle = const TextStyle(color: Colors.green); setState(() {}); } catch (e) { debugPrint('Exception: $e'); _status = '$e'; + _statusStyle = const TextStyle(color: Colors.red); + setState(() {}); } } @@ -99,6 +104,7 @@ class _MyHomePageState extends State<Configuration> { }catch(e){ debugPrint(e.toString()); _status = '$e'; + _statusStyle = const TextStyle(color: Colors.red); setState(() {}); } } @@ -196,8 +202,8 @@ class _MyHomePageState extends State<Configuration> { ); } if (snapshot.hasError) { - debugPrint('Some error happened'); - return const CircularProgressIndicator(); + debugPrint('Some error happened'); + return const CircularProgressIndicator(); } else{ return const CircularProgressIndicator(); @@ -209,8 +215,10 @@ class _MyHomePageState extends State<Configuration> { readOnly: true, autofocus: false, enabled: false, + style: _statusStyle, controller: TextEditingController( - text: _status), + text: _status, + ), ), const SizedBox(height: 15.0), @@ -232,11 +240,6 @@ class _MyHomePageState extends State<Configuration> { label: const Text('Dump Events'), onPressed: () { dumpToFile(); - - //TODO: remove before release this is not a real use case! - var db = DatabaseInstance(); - db.delete(); - //configuration.reset(); }, ), const SizedBox(width: 50), @@ -244,7 +247,7 @@ class _MyHomePageState extends State<Configuration> { heroTag: null, tooltip: 'Download corresponding devices and store locally', icon: const Icon(Icons.save), - label: const Text('Store'), + label: const Text('Set'), onPressed: () { updateConfiguration(); //TODO: display failed as user feedback somehow @@ -259,6 +262,5 @@ class _MyHomePageState extends State<Configuration> { } //TODO: write configuration on app dispose! -//TODO: display mission internet connection properly. //TODO: add label prefix with appended upcounting number. //TODO: grey out update button if nothing has changed. ? \ No newline at end of file diff --git a/lib/viewevents.dart b/lib/viewevents.dart index 63dcc4b863a7518b3f805491e0922bf00df103a3..b5f0c7c3ba15a1294f31768729600d02e98bcc7b 100644 --- a/lib/viewevents.dart +++ b/lib/viewevents.dart @@ -14,22 +14,23 @@ class ViewEvents extends StatefulWidget { class _ViewEvents extends State<ViewEvents> { // Get singleton to access locally stored events: final EventStoreInstance _events = EventStoreInstance(); - String _syncStatus = ''; + String _status = ''; + TextStyle _statusStyle = const TextStyle(color: Colors.black); var database = DatabaseInstance(); - List<Event> localEvents = []; + List<Event> _localEvents = []; Future<void> fetchEventsFromDb() async{ - localEvents = await database.getEvents(); - int pendingEventCnt = await database.getPendingEventCnt(); + _localEvents = await database.getEvents(); + int pendingEvents = await database.getPendingEventCnt(); - _syncStatus = pendingEventCnt.toString() + ' event(s) pending'; + _status = pendingEvents.toString() + ' event(s) pending'; + _statusStyle = const TextStyle(color: Colors.black); setState(() {}); //Got events from database, so update UI } @override void initState() { - _syncStatus = ''; super.initState(); fetchEventsFromDb(); } @@ -62,16 +63,18 @@ class _ViewEvents extends State<ViewEvents> { 'put success, remaining events: ' + syncCounter.toString()); event.status = 'EXPORTED'; //Update event to export only once database.updateEvent(event); //Update Event as exported in SQL Database - fetchEventsFromDb(); //update view list //TODO: this is bad for the sync performance! + await fetchEventsFromDb(); //update view list //TODO: this is bad for the sync performance! setState(() {}); } else { throw Exception('Sync for ' + event.urn + 'failed'); } } - _syncStatus = 'export success'; + _status = 'export success'; + _statusStyle = const TextStyle(color: Colors.green); } catch (e) { debugPrint('Exception: $e'); - _syncStatus = '$e'; + _status = '$e'; + _statusStyle = const TextStyle(color: Colors.red); setState(() {}); } }else{ @@ -163,7 +166,7 @@ class _ViewEvents extends State<ViewEvents> { ), ], rows: <DataRow>[ - for (var event in localEvents) + for (var event in _localEvents) DataRow( cells: <DataCell>[ DataCell(Text(event.urnId.toString())), @@ -238,7 +241,7 @@ class _ViewEvents extends State<ViewEvents> { mainAxisAlignment: MainAxisAlignment.end, children: [ const SizedBox(width: 10), - Text(_syncStatus), + Text(_status, style: _statusStyle), const SizedBox(width: 50), Container( margin: const EdgeInsets.symmetric(vertical: 10.0),