状态生成器在使用interactiveScrollViewer时不更新颤动列表



我正在使用InteractiveScrollViewer和列表不更新添加和更新功能,所以我使用StatefulBuilder为CardList。现在它的工作良好的同一页,但如果我推另一个页面,即endDrawer和更新项目那里当我弹出的页面,没有效果显示在页面。

StatefulBuilder(
builder:
(BuildContext context,
StateSetter _setState) =>

我正在更新项目列表在一些功能,是运行时抽屉关闭。我不能在这个函数中发送_setstate,因为这个函数是全局函数。

对于嵌套的滚动视图,我可以使用哪些其他技术?

编辑:

bloc.getAllFoodItems(_id).then((value) {
if (!mounted) return;
setState(() {
_itemList = value;
if (menuItemsList != null && menuItemsList.length != 0)
for (int i = 0; i < menuItemsList.length; i++) {
if (menuItemsList[i].id != null) {
int ls = -1;
if (_itemList != null)
ls = _itemList
.indexWhere((item) => item.itemID == menuItemsList[i].id);
if (ls != -1) {
setState(() {
menuItemsList[i].quantity = _itemList[ls].quantity;
});
} else
setState(() {
menuItemsList[i].quantity = 0;
});
}
}
});
});

此代码在draw关闭时运行。

你的问题是状态管理。

当你说你从另一个页面更新,那么主要问题是,你的抽屉可能没有全局保存状态,所以任何页面想要获得的信息来构建CardsList,将使用相同的信息。

现在主要的决策点是决定您想使用哪个状态管理系统。您可以使用以下任何选项,甚至更多:Provider、Bloc、InheritedWidget等。以下是官方Flutter文档中列出的许多选项:https://flutter.dev/docs/development/data-and-backend/state-mgmt/options

PS:对于简单的应用,我会推荐MobX或GetX,因为它减少了样板文件。

最新更新