display a maximum of three upcoming events on the home page

This commit is contained in:
Michael Thomas 2023-03-23 12:38:51 -04:00
parent cb9ccc1865
commit 662a1ae157
2 changed files with 24 additions and 19 deletions

View File

@ -83,15 +83,13 @@ class _HomeContentState extends State<HomeContent> {
), ),
const SizedBox(height: 20), const SizedBox(height: 20),
const HeaderWidget( const HeaderWidget(
title: "Today's Events", title: "Upcoming Events",
link: HeaderLink( link:
text: "View more", HeaderLink(text: "View more", href: EventsRoute()),
href: EventsRoute()
),
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 20), padding: const EdgeInsets.symmetric(horizontal: 20),
child: EventsList(), child: EventsList(limit: 3),
), ),
const HeaderWidget(title: "Food & Dining"), const HeaderWidget(title: "Food & Dining"),
const RestaurantsList(), const RestaurantsList(),

View File

@ -8,14 +8,17 @@ import 'event_card.dart';
class EventsList extends StatefulWidget { class EventsList extends StatefulWidget {
final DateTimeRange dateRange; final DateTimeRange dateRange;
final int? limit;
const EventsList._({ const EventsList._({
required this.dateRange, required this.dateRange,
this.limit,
Key? key, Key? key,
}) : super(key: key); }) : super(key: key);
factory EventsList({ factory EventsList({
DateTimeRange? dateRange, DateTimeRange? dateRange,
int? limit,
Key? key, Key? key,
}) { }) {
if (dateRange == null) { if (dateRange == null) {
@ -27,6 +30,7 @@ class EventsList extends StatefulWidget {
} }
return EventsList._( return EventsList._(
dateRange: dateRange, dateRange: dateRange,
limit: limit,
key: key, key: key,
); );
} }
@ -49,6 +53,9 @@ class _EventsListState extends State<EventsList> {
return event.time.isAfter(widget.dateRange.start) && return event.time.isAfter(widget.dateRange.start) &&
event.time.isBefore(widget.dateRange.end); event.time.isBefore(widget.dateRange.end);
}); });
if (widget.limit != null) {
events = events.take(widget.limit!);
}
if (events.isNotEmpty) { if (events.isNotEmpty) {
return Column( return Column(
children: events.map((event) { children: events.map((event) {