CalendarController constructor

CalendarController({
  1. CalendarSelectedMode selectMode = CalendarSelectedMode.singleSelect,
  2. int showMode = CalendarConstants.MODE_SHOW_ONLY_MONTH,
  3. int minYear = 1971,
  4. int maxYear = 2055,
  5. int minYearMonth = 1,
  6. int maxYearMonth = 12,
  7. int? nowYear,
  8. int? nowMonth,
  9. int minSelectYear = 1971,
  10. int minSelectMonth = 1,
  11. int minSelectDay = 1,
  12. int maxSelectYear = 2055,
  13. int maxSelectMonth = 12,
  14. int maxSelectDay = 30,
  15. Set<DateTime> selectedDateTimeList = EMPTY_SET,
  16. DateModel? selectDateModel,
  17. int maxMultiSelectCount = 9999,
  18. Map<DateModel, Object> extraDataMap = EMPTY_MAP,
  19. int offset = 0,
})

Implementation

CalendarController(
    {CalendarSelectedMode selectMode = CalendarSelectedMode.singleSelect,
    int showMode = CalendarConstants.MODE_SHOW_ONLY_MONTH,
    int minYear = 1971,
    int maxYear = 2055,
    int minYearMonth = 1,
    int maxYearMonth = 12,
    int? nowYear,
    int? nowMonth,
    int minSelectYear = 1971,
    int minSelectMonth = 1,
    int minSelectDay = 1,
    int maxSelectYear = 2055,
    int maxSelectMonth = 12,
    int maxSelectDay = 30,
    Set<DateTime> selectedDateTimeList = EMPTY_SET, //多选模式下,默认选中的item列表
    DateModel? selectDateModel, //单选模式下,默认选中的item
    int maxMultiSelectCount = 9999,
    Map<DateModel, Object> extraDataMap = EMPTY_MAP,
    int offset = 0 // 首日偏移量
    }) {
  assert(offset >= 0 && offset <= 6);
  LogUtil.log(TAG: this.runtimeType, message: "init CalendarConfiguration");
  Get.lazyPut(() => CalendarLogic()); ///添加初始化logic
  calendarLogic = Get.find<CalendarLogic>();

  //如果没有指定当前月份和年份,默认是当年时间
  if (nowYear == null) {
    nowYear = DateTime.now().year;
  }
  if (nowMonth == null) {
    nowMonth = DateTime.now().month;
  }
  calendarConfiguration = CalendarConfiguration(
      selectMode: selectMode,
      showMode: showMode,
      minYear: minYear,
      maxYear: maxYear,
      maxYearMonth: maxYearMonth,
      nowYear: nowYear,
      nowMonth: nowMonth,
      minSelectYear: minSelectYear,
      minSelectMonth: minSelectMonth,
      minYearMonth: minYearMonth,
      minSelectDay: minSelectDay,
      maxSelectYear: maxSelectYear,
      maxSelectMonth: maxSelectMonth,
      extraDataMap: extraDataMap,
      maxSelectDay: maxSelectDay,
      maxMultiSelectCount: maxMultiSelectCount,
      selectDateModel: selectDateModel ?? DateModel.fromDateTime(DateTime.now()),
      offset: offset);

  calendarConfiguration.defaultSelectedDateList = new HashSet<DateModel>();
  calendarConfiguration.defaultSelectedDateList
      ?.addAll(selectedDateTimeList.map((dateTime) {
    return DateModel.fromDateTime(dateTime);
  }).toSet());
  //将默认选中的数据,放到provider中
  calendarLogic.selectDateModel = selectDateModel ?? DateModel.fromDateTime(DateTime.now());
  calendarLogic.selectedDateList =
      calendarConfiguration.defaultSelectedDateList!;
  calendarConfiguration.minSelectDate = DateModel.fromDateTime(DateTime(
      calendarConfiguration.minSelectYear,
      calendarConfiguration.minSelectMonth,
      calendarConfiguration.minSelectDay));
  calendarConfiguration.maxSelectDate = DateModel.fromDateTime(DateTime(
      calendarConfiguration.maxSelectYear,
      calendarConfiguration.maxSelectMonth,
      calendarConfiguration.maxSelectDay));

  LogUtil.log(
      TAG: this.runtimeType,
      message: "start:${DateModel.fromDateTime(DateTime(
        minYear,
        minYearMonth,
      ))},end:${DateModel.fromDateTime(DateTime(
        maxYear,
        maxYearMonth,
      ))}");
  _weekAndMonthViewChange(showMode);
}