Articles in this section
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];
  });
}

View the GitHub sample here

Calendargif

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied