moveToCalendar method

void moveToCalendar(
  1. int year,
  2. int month,
  3. int day,
  4. {bool needAnimation = false,
  5. Duration duration = const Duration(milliseconds: 500),
  6. Curve curve = Curves.ease}
)

Implementation

void moveToCalendar(int year, int month, int day,
    {bool needAnimation = false,
    Duration duration = const Duration(milliseconds: 500),
    Curve curve = Curves.ease}) {
  if (calendarProvider.expandStatus.value == true) {
    DateModel dateModel = DateModel.fromDateTime(DateTime(year, month, 1));
    //计算目标索引
    int targetPage = monthList.indexOf(dateModel);
    if (targetPage == -1) {
      return;
    }
    if (calendarProvider.calendarConfiguration.monthController.hasClients ==
        false) {
      return;
    }
    if (needAnimation) {
      calendarProvider.calendarConfiguration.monthController
          .animateToPage(targetPage, duration: duration, curve: curve);
    } else {
      calendarProvider.calendarConfiguration.monthController
          .jumpToPage(targetPage);
    }
  } else {
    DateModel dateModel = DateModel.fromDateTime(DateTime(year, month, 1));
    //计算目标索引
    int targetPage = 0;
    for (int i = 0; i < weekList.length - 1; i++) {
      DateModel first = weekList[i];
      DateModel next = weekList[i + 1];
      if (!first.isAfter(dateModel) && next.isAfter(dateModel)) {
        targetPage = i;
        return;
      }
    }
    if (calendarProvider.calendarConfiguration.weekController.hasClients ==
        false) {
      return;
    }
    if (needAnimation) {
      calendarProvider.calendarConfiguration.weekController
          .animateToPage(targetPage, duration: duration, curve: curve);
    } else {
      calendarProvider.calendarConfiguration.weekController
          .jumpToPage(targetPage);
    }
  }
}