flutter calendar carousel 根据月份显示事件
flutter calendar carousel show events according to the month
我正在尝试使用 flutter 日历轮播构建一个日历应用程序。我需要做的是在用户滑动月份时显示分配给月份的事件。
checkCurrentMonth() {
selectedMonth = DateTime.parse(_targetDateTime.toString()).month.toInt();
selectedYear = DateTime.parse(_targetDateTime.toString()).year.toInt();
_markedDateMap.events.forEach((key, value) {
// print(_markedDateMap.events);
print(DateTime.parse(key.toString()).month.toInt());
if (selectedMonth == DateTime.parse(key.toString()).month.toInt() &&
selectedYear == DateTime.parse(key.toString()).year.toInt()) {
// print(_markedDateMap.events[key]);
_selectedHolidays.add(_markedDateMap.events[key]);
}
});
// for (var item in _selectedHolidays) {
// print("000000000000000 $item");
// gatheredEvents.add(GatherEvents.fromJson(item));
// }
print(_selectedHolidays[0].getTitle());
print(_markedDateMap.events.length);
}
我收到以下错误。
Class 'List<Event>' has no instance getter 'getTitle'.
Receiver: Instance(length:1) of '_GrowableList'
Tried calling: getTitle
这是我的 _markedDateMap
EventList<Event> _markedDateMap = new EventList<Event>(
events: {
new DateTime(2020, 12, 29): [
new Event(
date: new DateTime(2020, 12, 29),
title: 'Poya Day',
icon: _poyaeventIcon(DateTime(2020, 12, 29).day.toString()),
dot: Container(
margin: EdgeInsets.symmetric(horizontal: 1.0),
color: Colors.red,
height: 5.0,
width: 5.0,
),
),
],
new DateTime(2021, 01, 14): [
new Event(
date: new DateTime(2021, 01, 14),
title: 'Tamil Thai Pongal Day',
icon: _otheralleventIcon(DateTime(2021, 01, 14).day.toString()),
dot: Container(
margin: EdgeInsets.symmetric(horizontal: 1.0),
color: Colors.red,
height: 5.0,
width: 5.0,
),
),
],
},
);
请帮我解决这个问题。
除了本机 built-in 方法外,您不能在 List
上调用其他方法。您实际上是在 Event
的列表上调用方法 getTitle
。如果您想查看列表中所有事件的标题,您必须使用循环或获取特定索引。
for (var event in _selectedHolidays[0]) print(event.getTitle());
// or
print(_selectedHolidays[0].first.getTitle());
我正在尝试使用 flutter 日历轮播构建一个日历应用程序。我需要做的是在用户滑动月份时显示分配给月份的事件。
checkCurrentMonth() {
selectedMonth = DateTime.parse(_targetDateTime.toString()).month.toInt();
selectedYear = DateTime.parse(_targetDateTime.toString()).year.toInt();
_markedDateMap.events.forEach((key, value) {
// print(_markedDateMap.events);
print(DateTime.parse(key.toString()).month.toInt());
if (selectedMonth == DateTime.parse(key.toString()).month.toInt() &&
selectedYear == DateTime.parse(key.toString()).year.toInt()) {
// print(_markedDateMap.events[key]);
_selectedHolidays.add(_markedDateMap.events[key]);
}
});
// for (var item in _selectedHolidays) {
// print("000000000000000 $item");
// gatheredEvents.add(GatherEvents.fromJson(item));
// }
print(_selectedHolidays[0].getTitle());
print(_markedDateMap.events.length);
}
我收到以下错误。
Class 'List<Event>' has no instance getter 'getTitle'.
Receiver: Instance(length:1) of '_GrowableList'
Tried calling: getTitle
这是我的 _markedDateMap
EventList<Event> _markedDateMap = new EventList<Event>(
events: {
new DateTime(2020, 12, 29): [
new Event(
date: new DateTime(2020, 12, 29),
title: 'Poya Day',
icon: _poyaeventIcon(DateTime(2020, 12, 29).day.toString()),
dot: Container(
margin: EdgeInsets.symmetric(horizontal: 1.0),
color: Colors.red,
height: 5.0,
width: 5.0,
),
),
],
new DateTime(2021, 01, 14): [
new Event(
date: new DateTime(2021, 01, 14),
title: 'Tamil Thai Pongal Day',
icon: _otheralleventIcon(DateTime(2021, 01, 14).day.toString()),
dot: Container(
margin: EdgeInsets.symmetric(horizontal: 1.0),
color: Colors.red,
height: 5.0,
width: 5.0,
),
),
],
},
);
请帮我解决这个问题。
除了本机 built-in 方法外,您不能在 List
上调用其他方法。您实际上是在 Event
的列表上调用方法 getTitle
。如果您想查看列表中所有事件的标题,您必须使用循环或获取特定索引。
for (var event in _selectedHolidays[0]) print(event.getTitle());
// or
print(_selectedHolidays[0].first.getTitle());