controller property

CalendarController? controller

An object that used for programmatic date navigation and date selection in SfCalendar.

A CalendarController served for several purposes. It can be used to selected dates programmatically on SfCalendar by using the controller.selectedDate. It can be used to navigate to specific date by using the controller.displayDate property.

Listening to property changes:

The CalendarController is a listenable. It notifies it's listeners whenever any of attached SfCalendar`s selected date, display date changed (i.e: selecting a different date, swiping to next/previous view] in in SfCalendar.

In SfCalendar the visible view can be navigated programmatically by using the controller.forward and controller.backward method.

Programmatic selection:

In SfCalendar selecting dates programmatically can be achieved by using the controller.selectedDate which allows to select date on SfCalendar on initial load and in run time.

The CalendarController can be listened by adding a listener to the controller, the listener will listen and notify whenever the selected date, display date changed in the SfCalendar.

Defaults to null.

See also:

This example demonstrates how to use the CalendarController for SfCalendar.

class MyAppState extends State<MyApp>{

 CalendarController _calendarController;
   _calendarController = CalendarController();
   _calendarController.selectedDate = DateTime(2022, 02, 05);
   _calendarController.displayDate = DateTime(2022, 02, 05);

 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: SfCalendar(
         view: CalendarView.month,
         controller: _calendarController,


final CalendarController? controller;