Closed macMikey closed 6 days ago
hi @macMikey, if I understand your request correctly. You want to make one end of the range fixed, e.g. fixed startDate or endDate.
This is achievable with current implementation. What you need is to tweak the dates yield from the onValueChanged
. e.g.
value: _rangeDatePickerValueWithDefaultValue,
onValueChanged: (dates) {
setState(() => _rangeDatePickerValueWithDefaultValue = [
DateTime(1999, 5, 1),
dates.last
]);
}),
Above is an example of fixing the start date of a range.
that was suggestion 2. suggestion 1 was the one that is more interesting to me: don't clear the range when another date is selected, instead replace the one that is closest to the newly-selected date. there are any number of websites (say, for making hotel reservations) that reset the range rather than modifying it, which is really annoying.
I think this is still achievable with the current implementation - CalendarDatePicker2 does not hold any dates, the dates passed into it will be always rendered on the UI.
So if you want to modify the selection range to replace closest date, you will need to check which one is closer inside onValueChanged
and then modify the value passed into CalendarDatePicker2
. Take the example app as a sample and assume you already have a range selected.
value: _rangeDatePickerValueWithDefaultValue,
onValueChanged: (dates) {
setState(() {
// get the newly selectedDate: dates.first
// check selectedDate is closer to _rangeDatePickerValueWithDefaultValue.first or _rangeDatePickerValueWithDefaultValue.last
// replace _rangeDatePickerValueWithDefaultValue.first or _rangeDatePickerValueWithDefaultValue.last with the newy selected date
});
}),
that's if you build you own dialog. i was suggesting adding a feature to the library so someone does not have to build their own dialog.
This will be off the plan right now since it is only for the dialog method not the main widget.
Implement a custom dialog method shouldn't be too different and complex.
still a dart/flutter n00b, but, i managed to implement a feature i wanted, so now i'm proposing it, before i issue a PR:
use cases: