diff --git a/lib/configuration.dart b/lib/configuration.dart index 3bed95a..5786dd0 100644 --- a/lib/configuration.dart +++ b/lib/configuration.dart @@ -65,6 +65,8 @@ class CalendarConfiguration { ObserverList monthChangeListeners = ObserverList(); //保存多个月份监听的事件 + ObserverList weekChangeListeners = + ObserverList(); //周视图切换 /** * 下面的信息不是配置的,是根据配置信息进行计算出来的 diff --git a/lib/controller.dart b/lib/controller.dart index 2a71fb9..197ac7b 100644 --- a/lib/controller.dart +++ b/lib/controller.dart @@ -184,6 +184,11 @@ class CalendarController { calendarConfiguration.weekController = weekController; } + //周视图切换 + void addWeekChangeListener(OnWeekChange listener){ + this.calendarConfiguration.weekChangeListeners.add(listener); + } + //月份切换监听 void addMonthChangeListener(OnMonthChange listener) { // this.calendarConfiguration.monthChange = listener; @@ -532,6 +537,11 @@ bool defaultInRange(DateModel dateModel) { return true; } +/** + * 周视图切换 + */ +typedef void OnWeekChange(int year, int month); + /** * 月份切换事件 */ diff --git a/lib/widget/week_view_pager.dart b/lib/widget/week_view_pager.dart index 3a468c0..98b1b71 100644 --- a/lib/widget/week_view_pager.dart +++ b/lib/widget/week_view_pager.dart @@ -54,13 +54,17 @@ class _WeekViewPagerState extends State if (calendarProvider.expandStatus.value == true) { return; } + LogUtil.log( TAG: this.runtimeType, message: "WeekViewPager PageView onPageChanged,position:$position"); -// 周视图的变化 DateModel firstDayOfWeek = configuration.weekList[position]; int currentMonth = firstDayOfWeek.month; +// 周视图的变化 + configuration.weekChangeListeners.forEach((listener) { + listener(firstDayOfWeek.year, firstDayOfWeek.month); + }); if (lastMonth != currentMonth) { LogUtil.log( TAG: this.runtimeType,