CalendarController constructor
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, - DateModel? selectDateModel,
- int maxMultiSelectCount = 9999,
- Map<
DateModel, Object> extraDataMap = EMPTY_MAP, - 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);
}