onSelectionChanged property

DateRangePickerSelectionChangedCallback? onSelectionChanged
final

Called when the new dates or date ranges selected.

The dates or ranges that selected when the selection changes available in the DateRangePickerSelectionChangedArgs.

See also:


class MyAppState extends State<MyApp> {

 void _onSelectionChanged(DateRangePickerSelectionChangedArgs args) {
   if (args.value is PickerDateRange) {
     final DateTime rangeStartDate = args.value.startDate;
     final DateTime rangeEndDate = args.value.endDate;
   } else if (args.value is DateTime) {
     final DateTime selectedDate = args.value;
   } else if (args.value is List<DateTime>) {
     final List<DateTime> selectedDates = args.value;
   } else {
     final List<PickerDateRange> selectedRanges = args.value;
   }
 }

 @override
 Widget build(BuildContext context) {
   return MaterialApp(
       home: Scaffold(
     appBar: AppBar(
       title: Text('DatePicker demo'),
     ),
     body: SfDateRangePicker(
       onSelectionChanged: _onSelectionChanged,
       selectionMode: DateRangePickerSelectionMode.range,
       initialSelectedRange: PickerDateRange(
           DateTime.now().subtract(Duration(days: 4)),
           DateTime.now().add(Duration(days: 3))),
     ),
   ));
 }
}

Implementation

final DateRangePickerSelectionChangedCallback? onSelectionChanged;