To begin with, i have an event Map like this:
final Map<DateTime, List<CleanCalendarEvent>>? events;
It mapped all my event based on event Date. I want to select some events in certain range of date. I know how to select all the events in one selected date, and put it in a List.
_selectedEventsList = widget.events?[DateTime(_selectedDate.year, _selectedDate.month, _selectedDate.day)] ??[];
I want to select the all events in a week. How to do this with just Map? Can i just specify it in []?
2
Answers
You have to use from
package:collection
methodfirstWhereOrNull
and provide a predicate function to search required dates.For doing this you have take date with recent Sunday and next Sunday:
you can get all events within a week range with the following, with the following method: