From dafc20dd39811fa64b91bc3fe6a3554b2b43f655 Mon Sep 17 00:00:00 2001 From: LXD312569496 <450468291@qq.com> Date: Tue, 29 Oct 2019 20:38:11 +0800 Subject: [PATCH] =?UTF-8?q?controller=E6=8F=90=E4=BE=9BchangeExtraDataMap?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=8F=AF=E4=BB=A5=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=AE=9A=E4=B9=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?extraDataMap=E3=80=82=20=E6=9C=89=E5=9D=91=EF=BC=8C=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=94=A8=E5=88=B0ObjectKey=EF=BC=8C=E8=B7=9FFlutter?= =?UTF-8?q?=E7=9A=84=E5=88=B7=E6=96=B0=E6=9C=BA=E5=88=B6=E6=9C=89=E5=85=B3?= =?UTF-8?q?=E7=B3=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/controller.dart | 6 ++++++ lib/utils/date_util.dart | 4 ++++ lib/widget/month_view.dart | 11 +++++++++++ 3 files changed, 21 insertions(+) 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。 ); }); }