controller property
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.
Navigates to different view:
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:
- CalendarController, to know more about the controller and it's usage with the calendar.
- initialSelectedDate, to select dates initially on the calendar.
- initialDisplayDate, the date which shown when the calendar displayed initially.
- onViewChanged, the callback which notifies when the current view visible date changed on calendar.
- onSelectionChanged, the callback which notifies when the selected cell changed on the calendar.
- Knowledge base: How to programmatically navigate to adjacent days
- Knowledge base: How to do programmatic navigation
- Knowledge base: How to programmatically select the dates
- Knowledge base: How to move to a specific time while switching view
This example demonstrates how to use the CalendarController for SfCalendar.
class MyAppState extends State<MyApp>{
CalendarController _calendarController;
@override
initState(){
_calendarController = CalendarController();
_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,
),
),
);
}
}
Implementation
final CalendarController? controller;