display a maximum of three upcoming events on the home page
This commit is contained in:
parent
cb9ccc1865
commit
662a1ae157
|
@ -83,15 +83,13 @@ class _HomeContentState extends State<HomeContent> {
|
|||
),
|
||||
const SizedBox(height: 20),
|
||||
const HeaderWidget(
|
||||
title: "Today's Events",
|
||||
link: HeaderLink(
|
||||
text: "View more",
|
||||
href: EventsRoute()
|
||||
),
|
||||
title: "Upcoming Events",
|
||||
link:
|
||||
HeaderLink(text: "View more", href: EventsRoute()),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20),
|
||||
child: EventsList(),
|
||||
child: EventsList(limit: 3),
|
||||
),
|
||||
const HeaderWidget(title: "Food & Dining"),
|
||||
const RestaurantsList(),
|
||||
|
|
|
@ -8,14 +8,17 @@ import 'event_card.dart';
|
|||
|
||||
class EventsList extends StatefulWidget {
|
||||
final DateTimeRange dateRange;
|
||||
final int? limit;
|
||||
|
||||
const EventsList._({
|
||||
required this.dateRange,
|
||||
this.limit,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
factory EventsList({
|
||||
DateTimeRange? dateRange,
|
||||
int? limit,
|
||||
Key? key,
|
||||
}) {
|
||||
if (dateRange == null) {
|
||||
|
@ -27,6 +30,7 @@ class EventsList extends StatefulWidget {
|
|||
}
|
||||
return EventsList._(
|
||||
dateRange: dateRange,
|
||||
limit: limit,
|
||||
key: key,
|
||||
);
|
||||
}
|
||||
|
@ -46,21 +50,24 @@ class _EventsListState extends State<EventsList> {
|
|||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
var events = snapshot.data!.where((event) {
|
||||
return event.time.isAfter(widget.dateRange.start) &&
|
||||
event.time.isBefore(widget.dateRange.end);
|
||||
});
|
||||
if (events.isNotEmpty) {
|
||||
return Column(
|
||||
children: events.map((event) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15),
|
||||
child: EventCard(event),
|
||||
);
|
||||
}).toList());
|
||||
} else {
|
||||
return event.time.isAfter(widget.dateRange.start) &&
|
||||
event.time.isBefore(widget.dateRange.end);
|
||||
});
|
||||
if (widget.limit != null) {
|
||||
events = events.take(widget.limit!);
|
||||
}
|
||||
if (events.isNotEmpty) {
|
||||
return Column(
|
||||
children: events.map((event) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15),
|
||||
child: SizedBox(
|
||||
child: EventCard(event),
|
||||
);
|
||||
}).toList());
|
||||
} else {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 15),
|
||||
child: SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: Center(
|
||||
|
|
Loading…
Reference in New Issue