selectedDate property
DateTime?
get
selectedDate
The selected date in the SfCalendar.
Implementation
DateTime? get selectedDate => _selectedDate;
set
selectedDate
(DateTime? date)
Selects the given date programmatically in the SfCalendar by checking that the date falls in between the minimum and maximum date range
Note: If any date selected previously, will be removed and the selection will be drawn to the date given in this property.
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,
),
),
);
}
}
Implementation
set selectedDate(DateTime? date) {
if (CalendarViewHelper.isSameTimeSlot(_selectedDate, date)) {
return;
}
_selectedDate = date;
notifyPropertyChangedListeners('selectedDate');
}