list - Flutter AnimatedList 更新列表长度失败
问题描述
我正在实现一个 Flutter 应用程序并使用AnimatedList
. 在此列表中查看的数据是从控制器更新的,并且一旦完成任何更新,就会通知该列表。
当从控制器更新项目时,即添加或删除项目时,我调用setState
以更新视图。它被正确调用,构建方法被调用,动画列表读取新的列表长度,但它仍然显示旧的,因此它out of index
在列表末尾显示错误。
这就是我创建的方式AnimatedList
:
AnimatedList(
controller: controller,
key: GlobalKey(),
initialItemCount: list.length,
itemBuilder: (context, index, animation) {
//the item builder method
},
)
在Widget
我调用的控制器的侦听器中:
setState(() {
print('Update lists here');
});
那有什么问题呢?如何AnimatedList
使用控制器中的新列表更新并反映其新长度?
请注意,当我从使用列表中删除项目时,不会发生此错误Widget
:
listKey.currentState.removeItem(index, animationBuilder);
list.removeAt(index);
解决方案
推荐阅读
- javascript - 可交互/可点击的 HTML 图像图
- java - 属性文件似乎正在产生空指针异常?
- cpu-architecture - 带有流水线的 cpu 中的 CPI
- bash - 使用 bash 完成从 /dev 获取文件
- mysql - 创建存储过程以从表中选择并将行插入日志表
- javascript - 以特定格式显示数组
- sql - SQL 请求将值放入列中
- asp.net-mvc - 使用我自己的登录页面使用 MVC 向 Azure AD 进行身份验证
- android - 隐藏 Android SDK sdkmanager cli 命令的进度条
- css - 为什么异步加载 CSS 文件不能解析 PageSpeed 的“延迟未使用的 CSS”条目?