controller提供changeExtraDataMap方法,可以动态修改自定义数据extraDataMap。

有坑,需要用到ObjectKey,跟Flutter的刷新机制有关系
develop^2
LXD312569496 5 years ago committed by xiaodong
parent 389ce46a29
commit dafc20dd39

@ -214,6 +214,12 @@ class CalendarController {
}); });
} }
//extraDataMap
void changeExtraData(Map<DateModel, Object> newMap) {
this.calendarConfiguration.extraDataMap = newMap;
this.calendarProvider.generation.value++;
}
/** /**
* *
*/ */

@ -168,7 +168,11 @@ class DateUtil {
if (extraDataMap?.isNotEmpty == true) { if (extraDataMap?.isNotEmpty == true) {
if (extraDataMap.containsKey(dateModel)) { if (extraDataMap.containsKey(dateModel)) {
dateModel.extraData = extraDataMap[dateModel]; dateModel.extraData = extraDataMap[dateModel];
}else{
dateModel.extraData=null;
} }
}else{
dateModel.extraData=null;
} }
result.add(dateModel); result.add(dateModel);

@ -74,6 +74,16 @@ class _MonthViewState extends State<MonthView>
} }
lineCount = DateUtil.getMonthViewLineCount(widget.year, widget.month); lineCount = DateUtil.getMonthViewLineCount(widget.year, widget.month);
//
WidgetsBinding.instance.addPostFrameCallback((callback) {
Provider.of<CalendarProvider>(context, listen: false)
.generation
.addListener(() async {
extraDataMap={};
await getItems();
});
});
} }
getItems() async { getItems() async {
@ -130,6 +140,7 @@ class _MonthViewState extends State<MonthView>
return ItemContainer( return ItemContainer(
dateModel: dateModel, dateModel: dateModel,
key: ObjectKey(dateModel),//使objectKey1flutter2statefulElementstate
); );
}); });
} }

Loading…
Cancel
Save