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 (calendarLogic.expandStatus.value == true) {
    DateModel dateModel = DateModel.fromDateTime(DateTime(year, month, 1));
    //计算目标索引
    int targetPage = monthList.indexOf(dateModel);
    if (targetPage == -1) {
      return;
    }
    if (calendarLogic.calendarConfiguration.monthController!.hasClients ==
        false) {
      return;
    }
    if (needAnimation) {
      calendarLogic.calendarConfiguration.monthController
          ?.animateToPage(targetPage, duration: duration, curve: curve);
    } else {
      calendarLogic.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 (calendarLogic.calendarConfiguration.weekController!.hasClients ==
        false) {
      return;
    }
    if (needAnimation) {
      calendarLogic.calendarConfiguration.weekController
          ?.animateToPage(targetPage, duration: duration, curve: curve);
    } else {
      calendarLogic.calendarConfiguration.weekController
          ?.jumpToPage(targetPage);
    }
  }
}