onSelectionChanged property
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:
- onViewChanged, callback which notifies when the current view visible dates changed on date range picker.
- DateRangePickerMonthViewSettings.enableSwipeSelection, which allows to select the cells on swipe when the selection mode set as DateRangePickerSelectionMode.range, DateRangePickerSelectionMode.multiRange, and DateRangePickerSelectionMode.extendableRange.
- selectionMode, which allows to customize the selection mode with available mode options.
- allowViewNavigation, which allows to navigate between views quickly,
and setting this property as
false
, allows to select the cells on year, decade and century view of date range picker. - toggleDaySelection, which allows to deselect a date when the selection mode set as DateRangePickerSelectionMode.single.
- showActionButtons, which displays action buttons on bottom of date range picker, which allows to confirm and cancel the selection.
- onSubmit, callback which notifies when the selection confirmed through the ok button of showActionButtons.
- onCancel, callback which notifies when the selection canceled through the cancel button of showActionButtons.
- initialSelectedDate, which allows to select date programmatically initially on date range picker.
- initialSelectedDates, which allows to list of select date programmatically initially on date range picker.
- initialSelectedRange, which allows to select a range of dates programmatically initially on date range picker.
- initialSelectedRanges, which allows to select a ranges of dates programmatically initially on date range picker.
- DateRangePickerController.selectedDate,which allows to select date programmatically dynamically on date range picker.
- DateRangePickerController.selectedDates, which allows to select dates programmatically dynamically on date range picker.
- DateRangePickerController.selectedRange, which allows to select range of dates programmatically dynamically on date range picker.
- DateRangePickerController.selectedRanges, which allows to select ranges of dates programmatically dynamically on date range picker.
- Knowledge base: How to get the selected date
- Knowledge base: How to confirm or cancel the selection
- Knowledge base: How to select previous or next dates bases on selected date
- Knowledge base: How to get the start and end date of the selected range
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;