From 55dccadbb8ca53c322207af8e2dfb3deb2cfed03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hans-J=C3=BCrgen=20Tappe?= Date: Tue, 3 Dec 2024 20:48:13 +0100 Subject: [PATCH] Show only events starting in the future. --- lib/data/dataProviders/events_provider.dart | 16 ++++++++++++---- lib/pages/home_page.dart | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/data/dataProviders/events_provider.dart b/lib/data/dataProviders/events_provider.dart index 2f4615d..5534f49 100644 --- a/lib/data/dataProviders/events_provider.dart +++ b/lib/data/dataProviders/events_provider.dart @@ -145,16 +145,24 @@ class EventsProvider with ChangeNotifier { List filterPastEvents({ List? items, + bool withCurrent = true, }) { items ??= _items; if (items.isEmpty) { return []; } final DateTime now = DateTime.now(); - return items.where( - (item) => - item.end.isAfter(now) || - item.end.isAtSameMomentAs(now)).toList(); + if (withCurrent) { + return items.where( + (item) => + item.end.isAfter(now) || + item.end.isAtSameMomentAs(now)).toList(); + } else { + return items.where( + (item) => + item.start.isAfter(now) || + item.start.isAtSameMomentAs(now)).toList(); + } } List eventsByRoom({ diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 856d190..2f7b29b 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -63,7 +63,8 @@ class HomePageState extends State { final EventsProvider eventsProvider = Provider.of(context); _nextEventTime = eventsProvider.nextStartTime(); if (_remainingDuration <= Duration.zero) { - _upcomingEvents = eventsProvider.filterPastEvents().take(5).toList(); + _upcomingEvents = eventsProvider.filterPastEvents(withCurrent: false). + take(5).toList(); } return Scaffold(