所以我有这个地图final Map<DateTime, List<CleanCalendarEvent>>? events;
。我想根据DateTime从这个Map中获取一些项目,所以我这样做:
final recentSunday = DateTime(_selectedDate.year, _selectedDate.month,_selectedDate.day - _selectedDate.weekday % 7);
final nextSunday = DateTime(recentSunday.year, recentSunday.month, recentSunday.day + 7);
selectedCloseEvents = (widget.events?.firstWhereOrNull((date) =>
date.key.compareTo(recentSunday) > 0 &&
date.key.compareTo(nextSunday) < 0) ??
[])
这将以Map<DateTime, List<CleanCalendarEvent>>
格式返回一周内的所有事件。我需要它作为List<CleanCalendarEvent>
。
I have try:
_selectedCloseEvents = (widget.events?.firstWhereOrNull((date) =>
date.key.compareTo(recentSunday) > 0 &&
date.key.compareTo(nextSunday) < 0) ??
[])
.value as List<CleanCalendarEvent>?;
但它没有工作。如何从这个地图中只选择值?
根据文档,这应该会给您一个CleanCalenderEvent
的列表:
_selectedCloseEvents = selectedCloseEvents.values.toList()