selectedDate property
DateTime?
get
selectedDate
The selected date in the SfDateRangePicker.
It is only applicable when the selectionMode
set as
DateRangePickerSelectionMode.single for other selection modes this
property will return as null.
Implementation
DateTime? get selectedDate => _selectedDate;
set
selectedDate
(DateTime? date)
Selects the given date programmatically in the SfDateRangePicker 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.
If it is not null
the widget will render the date selection for the date
set to this property, even the SfDateRangePicker.initialSelectedDate is
not null.
It is only applicable when the DateRangePickerSelectionMode set as DateRangePickerSelectionMode.single.
See also:
- SfDateRangePicker.initialSelectedDate, which allows to select date programmatically initially on date range picker.
- selectedDates, which allows to select dates programmatically dynamically on date range picker.
- selectedRange, which allows to select range of dates programmatically dynamically on date range picker.
- selectedRanges, which allows to select ranges of dates programmatically dynamically on date range picker.
- SfDateRangePicker.selectionMode, which allows to customize the selection mode with available mode options.
- SfDateRangePicker.onSelectionChanged, the callback which notifies when the selected cell changed on the the date range picker.
- SfDateRangePicker.showActionButtons, which allows to cancel of confirm the selection in the date range picker.
- SfDateRangePicker.onSubmit, the callback which notifies when the selected value confirmed through confirm button on date range picker.
- SfDateRangePicker.onCancel, the callback which notifies when the selected value canceled and reverted to previous confirmed value through cancel button on date range picker.
- Knowledge base: How to get the selected date
- Knowledge base: How to programmatically select the date
class MyAppState extends State<MyApp> {
DateRangePickerController _pickerController =
DateRangePickerController();
@override
void initState() {
_pickerController.selectedDate = DateTime.now().add((Duration(
days: 4)));
super.initState();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SfDateRangePicker(
controller: _pickerController,
view: DateRangePickerView.month,
selectionMode: DateRangePickerSelectionMode.single,
showNavigationArrow: true,
),
),
);
}
}
Implementation
set selectedDate(DateTime? date) {
if (isSameDate(_selectedDate, date)) {
return;
}
_selectedDate = date;
notifyPropertyChangedListeners('selectedDate');
}