diff --git a/lib/controller.dart b/lib/controller.dart index 27bec8c..d61432b 100644 --- a/lib/controller.dart +++ b/lib/controller.dart @@ -214,6 +214,12 @@ class CalendarController { }); } + //可以动态修改extraDataMap + void changeExtraData(Map newMap) { + this.calendarConfiguration.extraDataMap = newMap; + this.calendarProvider.generation.value++; + } + /** * 月份或者星期的上一页 */ diff --git a/lib/utils/date_util.dart b/lib/utils/date_util.dart index 856feee..6f63d71 100644 --- a/lib/utils/date_util.dart +++ b/lib/utils/date_util.dart @@ -168,7 +168,11 @@ class DateUtil { if (extraDataMap?.isNotEmpty == true) { if (extraDataMap.containsKey(dateModel)) { dateModel.extraData = extraDataMap[dateModel]; + }else{ + dateModel.extraData=null; } + }else{ + dateModel.extraData=null; } result.add(dateModel); diff --git a/lib/widget/month_view.dart b/lib/widget/month_view.dart index 010dcf0..019ea69 100644 --- a/lib/widget/month_view.dart +++ b/lib/widget/month_view.dart @@ -74,6 +74,16 @@ class _MonthViewState extends State } lineCount = DateUtil.getMonthViewLineCount(widget.year, widget.month); + + //第一帧后 + WidgetsBinding.instance.addPostFrameCallback((callback) { + Provider.of(context, listen: false) + .generation + .addListener(() async { + extraDataMap={}; + await getItems(); + }); + }); } getItems() async { @@ -130,6 +140,7 @@ class _MonthViewState extends State return ItemContainer( dateModel: dateModel, + key: ObjectKey(dateModel),//这里使用objectKey,保证可以刷新。原因1:跟flutter的刷新机制有关。原因2:statefulElement持有state。 ); }); }