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

added switch to show all events. Default only show pending events due to performance reasons

parent ee74529d
No related branches found
No related tags found
No related merge requests found
......@@ -391,6 +391,7 @@ class ConfigurationStoreInstance extends ConfigurationStoreBase {
abstract class EventStoreBase{
bool gnssSync = true;
bool showAllEvents = false;
Event currentEvent = Event(
id: 0,
urnId:-1,
......@@ -410,13 +411,15 @@ abstract class EventStoreBase{
Map<String, dynamic> toMap() {
return {
'currentEvent' : currentEvent.toJson(),
'gnssSync' : gnssSync
'gnssSync' : gnssSync,
'showAllEvents' : showAllEvents
};
}
void fromMap(Map<String, dynamic> map) {
currentEvent = Event.fromJson(map['currentEvent']);
gnssSync = map['gnssSync'];
showAllEvents = map['showAllEvents'];
}
}
......
......@@ -15,17 +15,30 @@ class _ViewEvents extends State<ViewEvents> {
final EventStoreInstance _events = EventStoreInstance();
String _status = '';
TextStyle _statusStyle = const TextStyle(color: Colors.black);
String _appBarText = '';
var database = DatabaseInstance();
List<Event> _localEvents = [];
Future<void> fetchEventsFromDb() async{
_localEvents = await database.getEvents();
int pendingEvents = await database.getPendingEventCnt();
final EventStoreInstance event = EventStoreInstance();
int pendingEvents = 0;
if (event.showAllEvents == false) {
_appBarText = 'Pending Events';
//Get only pending events
_localEvents = await database.getPendingEvents();
pendingEvents = _localEvents.length;
}else {
_appBarText = 'All Events';
_localEvents = await database.getEvents();
pendingEvents = await database.getPendingEventCnt();
}
_status = pendingEvents.toString() + ' event(s) pending';
_statusStyle = const TextStyle(color: Colors.black);
setState(() {}); //Got events from database, so update UI
setState(() {}); //Got events from database, so update UI
}
@override
......@@ -84,9 +97,20 @@ class _ViewEvents extends State<ViewEvents> {
@override
Widget build(BuildContext context) {
final EventStoreInstance event = EventStoreInstance();
return Scaffold(
appBar: AppBar(
title: const Text("View & Sync"),
actions: <Widget>[
Text(_appBarText, style: const TextStyle(fontStyle: FontStyle.italic),),
Switch( //Enable showing all or only pending events. Default is to show only pending events
value: event.showAllEvents,
onChanged: (value) {
event.showAllEvents = value;
fetchEventsFromDb();
setState(() {});
}),
],
),
body: Container(
margin: const EdgeInsets.symmetric(horizontal: 5.0),
......@@ -260,3 +284,4 @@ class _ViewEvents extends State<ViewEvents> {
}
}
//TODO: allow editing fields here.
//TODO: show only pending events.
\ No newline at end of file
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