Category / Section
How to programmatically select the dates in the Flutter Calendar
In the Flutter Event Calendar, you can programmatically select the date using selectedDate property of the CalendarController.
Inside your state class, initialize the calendar controller:
final CalendarController _calendarController= CalendarController();
Using onViewChanged callback of the Flutter event calendar to set the first date of visible dates as the selected date
child: SfCalendar(
view: CalendarView.month,
controller: _calendarController,
onViewChanged: viewChanged,
),
void viewChanged(ViewChangedDetails viewChangedDetails) {
SchedulerBinding.instance!.addPostFrameCallback((Duration duration) {
_calendarController.selectedDate = viewChangedDetails.visibleDates[0];
});
}
|
