selectedDates property

List<DateTime>? selectedDates

The list of dates selected in the SfDateRangePicker.

It is only applicable when the selectionMode set as DateRangePickerSelectionMode.multiple for other selection modes this property will return as null.

Implementation

List<DateTime>? get selectedDates => _selectedDates;
void selectedDates=(List<DateTime>? dates)

Selects the given dates programmatically in the SfDateRangePicker by checking that the dates falls in between the minimum and maximum date range.

Note: If any list of dates selected previously, will be removed and the selection will be drawn to the dates set to this property.

If it is not null the widget will render the date selection for the dates set to this property, even the SfDateRangePicker.initialSelectedDates is not null.

It is only applicable when the selectionMode set as DateRangePickerSelectionMode.multiple.

See also:


class MyAppState extends State<MyApp> {
DateRangePickerController _pickerController = DateRangePickerController();

 @override
 void initState() {
   _pickerController.selectedDates = <DateTime>[
     DateTime.now().add((Duration(days: 4))),
     DateTime.now().add((Duration(days: 7))),
     DateTime.now().add((Duration(days: 8)))
   ];
   super.initState();
 }

 @override
 Widget build(BuildContext context) {
   return MaterialApp(
     home: Scaffold(
       body: SfDateRangePicker(
         controller: _pickerController,
         view: DateRangePickerView.month,
         selectionMode: DateRangePickerSelectionMode.multiple,
         showNavigationArrow: true,
       ),
     ),
   );
 }
}

Implementation

set selectedDates(List<DateTime>? dates) {
  if (DateRangePickerHelper.isDateCollectionEquals(_selectedDates, dates)) {
    return;
  }

  _selectedDates = DateRangePickerHelper.cloneList(dates)?.cast<DateTime>();
  notifyPropertyChangedListeners('selectedDates');
}