@@ -250,7 +250,7 @@ class DatePickerController {
250250 curve: curve);
251251 }
252252
253- /// This function will animate to any date that is passed as a parameter
253+ /// This function will animate to any date that is passed as an argument
254254 /// In case a date is out of range nothing will happen
255255 void animateToDate (DateTime date,
256256 {duration = const Duration (milliseconds: 500 ), curve = Curves .linear}) {
@@ -261,6 +261,24 @@ class DatePickerController {
261261 duration: duration, curve: curve);
262262 }
263263
264+ /// This function will animate to any date that is passed as an argument
265+ /// this will also set that date as the current selected date
266+ void setDateAndAnimate (DateTime date,
267+ {duration = const Duration (milliseconds: 500 ), curve = Curves .linear}) {
268+ assert (_datePickerState != null ,
269+ 'DatePickerController is not attached to any DatePicker View.' );
270+
271+ _datePickerState! ._controller.animateTo (_calculateDateOffset (date),
272+ duration: duration, curve: curve);
273+
274+ if (date.compareTo (_datePickerState! .widget.startDate) >= 0 &&
275+ date.compareTo (_datePickerState! .widget.startDate.add (
276+ Duration (days: _datePickerState! .widget.daysCount))) <= 0 ) {
277+ // date is in the range
278+ _datePickerState! ._currentDate = date;
279+ }
280+ }
281+
264282 /// Calculate the number of pixels that needs to be scrolled to go to the
265283 /// date provided in the argument
266284 double _calculateDateOffset (DateTime date) {
0 commit comments