CalendarController class

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 selectedDate. It can be used to navigate to specific date by using the 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 forward and backward method.

Programmatic selection:

In SfCalendar selecting dates programmatically can be achieved by using the 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.

This example demonstrates how to use the CalendarController for SfCalendar.


class MyAppState extends State<MyApp>{

 CalendarController _calendarController = CalendarController();
 @override
 initState(){
   _calendarController.selectedDate = DateTime(2022, 02, 05);
   _calendarController.displayDate = DateTime(2022, 02, 05);
   super.initState();
 }

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

Constructors

CalendarController()

Properties

backward VoidCallback?
Moves to the previous view programmatically with animation by checking that the previous view dates falls between the minimum and maximum date range.
getter/setter pair
displayDate DateTime?
The first date of the current visible view, when the view set with the view other than CalendarView.month.
getter/setter pair
forward VoidCallback?
Moves to the next view programmatically with animation by checking that the next view dates falls between the minimum and maximum date range.
getter/setter pair
getCalendarDetailsAtOffset CalendarDetailsCallback?
Get the calendar details by given the Offset by using the getCalendarDetailsAtOffset method.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
selectedDate DateTime?
The selected date in the SfCalendar.
getter/setter pair
view CalendarView?
The displayed view of the SfCalendar.
getter/setter pair

Methods

addPropertyChangedListener(CalendarValueChangedCallback listener) → void
Calls the listener every time the controller's property changed.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
dispose() → void
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener and removeListener will throw after the object is disposed).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyPropertyChangedListeners(String property) → void
Call all the registered listeners.
inherited
removePropertyChangedListener(CalendarValueChangedCallback listener) → void
remove the listener used for notify the data source changes.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited