Flutter Table 日历:CalendarController 问题
Flutter Table Calendar: CalendarController Question
所以根据 table 日历版本的变更日志。 3.0.0,CalendarController
被移除。我的代码中有它,现在显示为错误 Undefined class 'CalendarController'。现在,我想知道该怎么办,因为我在任何地方都找不到答案。
另外,有人可以向我解释一下 CalendarController
的用途吗?
任何帮助将不胜感激,谢谢!!
如变更日志所述,CalendarController 在较新版本中已被删除。
它用于突出显示的(当前选择的)日功能。
您可以通过将这些属性添加到 TableCalender():
来手动配置选定的日期
selectedDayPredicate: (day) {
// Use `selectedDayPredicate` to determine which day is currently selected.
// If this returns true, then `day` will be marked as selected.
// Using `isSameDay` is recommended to disregard
// the time-part of compared DateTime objects.
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
if (!isSameDay(_selectedDay, selectedDay)) {
// Call `setState()` when updating the selected day
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
}
},
onFormatChanged: (format) {
if (_calendarFormat != format) {
// Call `setState()` when updating calendar format
setState(() {
_calendarFormat = format;
});
}
},
onPageChanged: (focusedDay) {
// No need to call `setState()` here
_focusedDay = focusedDay;
},
还要确保定义 firstDay:、lastDay: 和 focusedDay: 因为 TableCalendar() 函数需要它,还要设置日历格式。
参考官方table_calendar例子:https://github.com/aleksanderwozniak/table_calendar/blob/master/example/lib/pages/basics_example.dart
所以根据 table 日历版本的变更日志。 3.0.0,CalendarController
被移除。我的代码中有它,现在显示为错误 Undefined class 'CalendarController'。现在,我想知道该怎么办,因为我在任何地方都找不到答案。
另外,有人可以向我解释一下 CalendarController
的用途吗?
任何帮助将不胜感激,谢谢!!
如变更日志所述,CalendarController 在较新版本中已被删除。 它用于突出显示的(当前选择的)日功能。
您可以通过将这些属性添加到 TableCalender():
来手动配置选定的日期selectedDayPredicate: (day) {
// Use `selectedDayPredicate` to determine which day is currently selected.
// If this returns true, then `day` will be marked as selected.
// Using `isSameDay` is recommended to disregard
// the time-part of compared DateTime objects.
return isSameDay(_selectedDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
if (!isSameDay(_selectedDay, selectedDay)) {
// Call `setState()` when updating the selected day
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusedDay;
});
}
},
onFormatChanged: (format) {
if (_calendarFormat != format) {
// Call `setState()` when updating calendar format
setState(() {
_calendarFormat = format;
});
}
},
onPageChanged: (focusedDay) {
// No need to call `setState()` here
_focusedDay = focusedDay;
},
还要确保定义 firstDay:、lastDay: 和 focusedDay: 因为 TableCalendar() 函数需要它,还要设置日历格式。
参考官方table_calendar例子:https://github.com/aleksanderwozniak/table_calendar/blob/master/example/lib/pages/basics_example.dart