setDateAndAnimate method

void setDateAndAnimate(
  1. DateTime date, {
  2. dynamic duration = const Duration(milliseconds: 500),
  3. dynamic curve = Curves.linear,
})

This function will animate to any date that is passed as an argument this will also set that date as the current selected date

Implementation

void setDateAndAnimate(DateTime date,
    {duration = const Duration(milliseconds: 500), curve = Curves.linear}) {
  assert(_datePickerState != null,
      'DatePickerController is not attached to any DatePicker View.');

  _datePickerState!._controller.animateTo(_calculateDateOffset(date),
      duration: duration, curve: curve);

  DateTime compareDate = DateTime(_datePickerState!._currentDate.year,
      _datePickerState!._currentDate.month, 0);

  if (date.compareTo(compareDate) >= 0 &&
      date.compareTo(
              compareDate.add(Duration(days: _datePickerState!.totalDays))) <=
          0) {
    // date is in the range
    _datePickerState!._currentDate = date;
  }
}