selectedRanges property

List<PickerDateRange>? get selectedRanges

List of selected ranges in the SfDateRangePicker.

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

Implementation

List<PickerDateRange>? get selectedRanges => _selectedRanges;
set selectedRanges (List<PickerDateRange>? ranges)

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

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

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

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

See also:


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

 @override
 void initState() {
   _pickerController.selectedRanges = <PickerDateRange>[
     PickerDateRange(DateTime.now().subtract(Duration(days: 4)),
         DateTime.now().add(Duration(days: 4))),
     PickerDateRange(DateTime.now().add(Duration(days: 11)),
         DateTime.now().add(Duration(days: 16)))
   ];
   super.initState();
 }

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

Implementation

set selectedRanges(List<PickerDateRange>? ranges) {
  if (DateRangePickerHelper.isDateRangesEquals(_selectedRanges, ranges)) {
    return;
  }

  _selectedRanges =
      DateRangePickerHelper.cloneList(ranges)?.cast<PickerDateRange>();
  notifyPropertyChangedListeners('selectedRanges');
}