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

View sample in GitHub

Calendargif

 

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