Display Events on the Calendar and Filter by Selected Date
Scenario: Imagine you have an app where users can view events and appointments, and you want to allow them to select a date on the calendar to see the events that are happening on that day. When a date is selected, the events should automatically be filtered and displayed in a list on the same page.

Steps to implement
Set up the Calendar
Make the query accessible
To avoid making unnecessary multiple queries, it is recommended to place the main query at the top of the layout. This way, all widgets that need to use the information from that query will have access to it. Some users may choose to wrap the calendar inside a container and make the query within that container. However, this is not recommended because no other element on the page will be able to access that query. As a result, you would be forced to create a second query if you want to display a filtered list of events based on the selected date from the calendar
Pass a list of datetimes to the calendar
Use the eventsDates parameter to pass a list of event dates. This list should come from the query in the main container of your page, and the source of that query can be any data management system, such as Supabase, Firestore, or others. If you cannot directly access the list of DateTime objects (for instance, if the dates are stored within a list of Firestore documents or Supabase rows), you can use FlutterFlow’s built-in option to map the field containing the DateTime for each item in the query. This will extract the DateTime field from each item in the query results, and you can pass the resulting list of DateTime objects to the calendar.
Filter events
Apply a Date Filter Based on the Calendar Selection
Use a filter where the field containing the event’s date (formatted as "d/m/y") is compared with the selected date from the calendar, which is stored as pageState > CustomCalendar > selectedDate (formattedd as "d/m/y").
Important:
It’s crucial to format both the event date and the selected calendar date to "d/m/y" because the time part (00:00) in the calendar’s selected date might not match the time in the event data. Without this formatting, only events with a time of 00:00 would match. By formatting both the event date and the selected date to "d/m/y," you ensure that the comparison is based only on the date, ignoring the time.
Last updated