XBCalendarVM constructor
XBCalendarVM({
- required BuildContext context,
Implementation
XBCalendarVM({required super.context}) {
markDates = widget.initMarkDates;
_dataStreamSubscription = widget.dataStream?.listen((event) {
markDates = event.markDates;
if (markDates == null) return;
for (var element in years.values) {
element.updateMark(markDates);
}
notify();
});
isSingle = widget.isSingle;
tempContext ??= context;
createDateTime = DateTime.now();
minDateTime = widget.minDateTime ?? DateTime(createYear - 25, 1);
maxDateTime = widget.maxDateTime ?? DateTime(createYear + 25, 1);
for (int i = minDateTime.year; i <= maxDateTime.year; i++) {
if (i < minDateTime.year || i > maxDateTime.year) continue;
years[i] = XBCalendarYear(
year: i,
minDateTime: minDateTime,
maxDateTime: maxDateTime,
minEnableDateTime: widget.minEnableDateTime,
maxEnableDateTime: widget.maxEnableDateTime,
markDates: markDates);
}
selectedDates = widget.selectedDates ?? [];
selectedDates.sort();
updateYears();
controller = ScrollController(initialScrollOffset: initOffset);
controller.addListener(offsetListener);
weekDaysWidgets = weekDays
.map((day) => Expanded(child: Center(child: Text(day))))
.toList();
_calcScrollYearInt();
_calcScrollMonthInt();
}