flutter - Flutter - Flutter bloc 状态未更新
问题描述
我正在使用flutter_bloc
库来管理小部件的状态。我正在尝试更新状态为List
. 当我捕获状态并修改所需值,然后产生新状态时,状态不会更新,但状态的克隆会更改。
Stream<ItemState> _updateRestrictions(ItemUpdateRestrictionValue event) async * {
if (state is ItemLoaded) {
final restrictions = (state as ItemLoaded).restrictions;
final newState = restrictions.map((restriction) {
if (restriction.id == event.restrictionId) {
return ItemRestriction(
id: restriction.id,
name: restriction.name,
restrictionType: restriction.restrictionType,
restrictionValues: restriction.restrictionValues,
restrictionValue: event.restrictionValueId
);
}
return restriction;
}).toList();
yield ItemLoaded(restrictions: newState);
}
}
难道我做错了什么?或者你如何flutter_bloc
正确使用更新状态?
解决方案
这可能会发生,因为你使用Equatable
你的ItemState class
并产生相同的状态,即IteamLoaded()
.
您可能想阅读此https://bloclibrary.dev/#/faqs?id=when-to-use-equatable
推荐阅读
- python - 有没有办法检查graphviz中是否已经存在节点?
- selenium-webdriver - 使用 webdrivermanager 找不到 Opera 二进制错误 selenium+java
- jquery - bootstrap 4将按钮放在上紧角
- asp.net-mvc - 与 ASP MVC 集成时,mdb-icon 在 Angular 中不起作用
- r - 无法弄清楚我的 R 函数代码中缺少什么 - 阻止它正常运行
- java - Swingutilities.invokeLater 和 while 循环
- php - FB分享按钮的URL中获取不同的APP key
- python-3.x - NLP 结构问题(进行特征提取的最佳方法)
- reactjs - ReactJS - 状态更改后重定向到私有路由
- java - 使用反射使用子类获取超类字段