Reputation: 25
So according to the changelog of table calendar ver. 3.0.0, CalendarController
is removed. I have it on my codes and it's now showing up as an error Undefined class 'CalendarController'. And now, I'm wondering what to do about it because i've found no answers to it anywhere.
Also, can someone explain to me what was the use of CalendarController
in the first place?
Any help would be appreciated, thank you!!
Upvotes: 2
Views: 5411
Reputation: 164
Like the changelog says, CalendarController is removed in the newer version. It was used for the highlighted (currently selected) day functionalities.
You can manually configure the selected day by adding these attributes to the 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;
},
Also make sure to define firstDay:, lastDay:, and focusedDay: because it is required by the TableCalendar() function, and also set the calendarFormat.
Refer official table_calendar example: https://github.com/aleksanderwozniak/table_calendar/blob/master/example/lib/pages/basics_example.dart
Upvotes: 3