range method

Widget range({
  1. required CalendarInfo calendarInfo,
  2. required DateInfo date,
  3. required double width,
  4. required int index,
})

Implementation

Widget range({
  required CalendarInfo calendarInfo,
  required DateInfo date,
  required double width,
  required int index,
}) {
  return InkWell(
    onTap: () {
      if (date.date != null) {
        if (date.isSelected != SelectType.empty) {
          if (date.isSelected != SelectType.disabled) {
            setState(() {
              if (calendarInfo.dates.length > 0) {
                DateTime selectedDates = DateTime(
                    calendarInfo.year, calendarInfo.month, date.date!);
                if (datesRange.start != null && datesRange.end != null) {
                  resetCalendar();
                  setStart(date: date, selectedDates: selectedDates);
                  setBottomStartFormat(
                      yyyy: calendarInfo.year,
                      mm: calendarInfo.month,
                      dd: date.date);
                  date.singleSelectedAniCtrl!.forward();
                  bottomBorderExpandCtrl.reverse();
                } else if (datesRange.start != null) {
                  if (datesRange.start!.compare(selectedDates)) {
                    resetCalendar();
                    bottomBorderCtrl.reverse();
                  } else {
                    if (datesRange.start!.isBefore(selectedDates)) {
                      date.isSelected = SelectType.end;
                      datesRange.end = selectedDates;
                      datesRange.start = datesRange.start;
                      setBottomEndFormat(
                          yyyy: datesRange.end!.year,
                          mm: datesRange.end!.month,
                          dd: datesRange.end!.day);
                      date.singleSelectedAniCtrl!.forward();
                      setBottomStartFormat(
                          yyyy: datesRange.start!.year,
                          mm: datesRange.start!.month,
                          dd: datesRange.start!.day);
                      bottomBorderCtrl.forward();
                      bottomBorderExpandCtrl.forward();
                    } else {
                      date.isSelected = SelectType.start;

                      datesRange.end = DateTime(
                          // 깊은 복사
                          datesRange.start!.year,
                          datesRange.start!.month,
                          datesRange.start!.day);
                      setBottomStartFormat(
                          yyyy: selectedDates.year,
                          mm: selectedDates.month,
                          dd: selectedDates.day);
                      setBottomEndFormat(
                          yyyy: datesRange.end!.year,
                          mm: datesRange.end!.month,
                          dd: datesRange.end!.day);
                      datesRange.start = selectedDates;
                      date.singleSelectedAniCtrl!.forward();

                      for (var element in calendarInfo.dates) {
                        if (element.date == datesRange.end!.day) {
                          if (datesRange.end!.month == calendarInfo.month) {
                            element.isSelected = SelectType.end;
                            date.singleSelectedAniCtrl!.forward();
                            bottomBorderCtrl.forward();
                            bottomBorderExpandCtrl.forward();
                          } else {
                            if (element.isSelected == SelectType.disabled) {
                              element.isSelected = SelectType.disabled;
                            } else {
                              element.isSelected = SelectType.none;
                              element.singleSelectedAniCtrl!.reverse();
                            }
                          }
                        }
                      }
                    }
                    // start 데이트 셋팅
                    DateTime currentMonthStartDate = (datesRange
                                .start!.month ==
                            calendarInfo.month) // 달이 같을 때와 다를 때
                        ? datesRange.start!.year !=
                                calendarInfo.year // 연도가 같을 때와 다를 때
                            ? DateTime(
                                calendarInfo.year, calendarInfo.month, 0)
                            : datesRange.start!
                        : DateTime(calendarInfo.year, calendarInfo.month, 0);
                    DateTime currentMonthEndDate = (datesRange.end!.month ==
                            calendarInfo.month)
                        ? datesRange.end!.year != calendarInfo.year
                            ? DateTime(
                                calendarInfo.year, calendarInfo.month + 1, 1)
                            : datesRange.end!
                        : DateTime(
                            calendarInfo.year, calendarInfo.month + 1, 1);
                    bottomRangeBtnCtrl.forward();
                    bottomBorderExpandCtrl.forward();
                    // between 셋팅
                    int startIndex;
                    int endIndex;
                    if (datesRange.start != null && datesRange.end != null) {
                      if (currentMonthEndDate.day -
                              currentMonthStartDate.day !=
                          1) {
                        List<DateTime> actualBetweenDates =
                            currentMonthStartDate.getBtwDates(
                                end: currentMonthEndDate);
                        startIndex = calendarInfo.dates.indexWhere(
                            (datesIndex) =>
                                datesIndex.date == actualBetweenDates[0].day);
                        endIndex = calendarInfo.dates.indexWhere(
                            (datesIndex) =>
                                datesIndex.date ==
                                actualBetweenDates[
                                        actualBetweenDates.length - 1]
                                    .day);
                        for (var btwDate1 in actualBetweenDates) {
                          for (var element1 in calendarInfo.dates) {
                            if (element1.isSelected != SelectType.disabled) {
                              if (element1.date == btwDate1.day) {
                                element1.isSelected = SelectType.between;
                              }
                            }
                          }
                        }
                      } else {
                        startIndex = calendarInfo.dates.indexWhere(
                            (datesIndex) =>
                                datesIndex.date == currentMonthStartDate.day);
                        endIndex = calendarInfo.dates.indexWhere(
                            (datesIndex) =>
                                datesIndex.date == currentMonthEndDate.day);
                      }
                      setOrderRangeAnimation(
                          currentMonthStartDate.month == calendarInfo.month
                              ? startIndex - 1
                              : startIndex,
                          currentMonthEndDate.month == calendarInfo.month
                              ? endIndex + 1
                              : endIndex);
                    }
                  }
                } else {
                  setStart(date: date, selectedDates: selectedDates);
                  setBottomStartFormat(
                      yyyy: calendarInfo.year,
                      mm: calendarInfo.month,
                      dd: date.date);
                  bottomBorderCtrl.forward();
                  date.singleSelectedAniCtrl!.forward();
                  setBottomStartFormat(
                      yyyy: calendarInfo.year,
                      mm: calendarInfo.month,
                      dd: date.date);
                }
                // setRangeSelect();
              }
            });
            if (datesRange.start != null && datesRange.end != null) {
              // setRangeSelect();
            }
            // setSizedBottomRightBtn(
            //                               defaultSize: width * 0.06,
            //                               oneSelectedSize: width * 0.045,
            //                               multipleSelectedSize:
            //                                   width * 0.03);
          }
        }
      }
    },
    child: Container(
      width: width / 7,
      height: width / 9,
      child: Stack(
        children: [
          outerCircle(date, width, index),
          startArea(date, width, index),
          betweenArea(date, width, index),
          endArea(date, width, index),
          innerCircle(date, width, index),
          Align(
            alignment: Alignment.center,
            child: date.date != null
                ? Text(date.date.toString(),
                    style: TextStyle(
                      fontSize: width * 0.033,
                      color: textColor(date.isSelected),
                    ))
                : Container(),
          )
        ],
      ),
    ),
  );
}