Category / Section
How to programmatically select the dates in the Flutter Calendar
1 min read
In the Flutter Event Calendar, you can programmatically select the date using selectedDate property of the CalendarController.
Inside the state, initialize the calendar controller.
final CalendarController _calendarController= CalendarController();
Using onViewChanged callback of the Flutter event calendar, you can set the first date of visible dates as 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]; }); }