flutter - Listview builder不更新列表中的值
问题描述
我在 Stack 中有一个定位的 ListViewBuilder,试图在具有不同下拉值的多个图块中显示动态下拉列表。这似乎工作正常,除了当列表用新值更新并在 SetState 上刷新时,这些值似乎没有正确清除。
ListView 构建器代码
Positioned(
top: 100,
left: 100,
width: 90,
height: MediaQuery.of(context).size.height,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: dropDownListValues.length,
itemBuilder: (context, index) {
return Tile(
tileId: dropDownListValues[index],
isHeaderTile: false,
uuid: Uuid().v1(),
);
},
),
),
根据按下的按钮清除和更新列表。
void _toggleDropDown(List valueList) {
if (dropDownListValues.isEmpty) {
setState(() {
dropDownListValues = valueList;
});
} else {
setState(() {
dropDownListValues.clear();
});
}
}
我最终得到的是列表根据下拉列表中的项目数进行扩展,但是上一个列表中的值从最后一个列表中继承..
例子。
下拉列表值
Dropdown list 1 = ['one', 'two']
Dropdown list 2 = ['two', 'three', 'four']
我看到的是
Dropdown list 1 = ['one', 'two']
Dropdown list 2 = ['one', 'two', 'four']
如果我首先单击列表两个下拉列表,我会得到以下信息
Dropdown list 1 = ['two', 'three']
Dropdown list 2 = ['two', 'three', 'four']
我被难住了,花了几个小时在这上面,知道我做错了什么会导致这个刷新问题吗?
提前致谢。
解决方案
尝试使用keys
,以便 Flutter 框架可以识别列表的更改。
推荐阅读
- intellij-idea - 如何更改 RubyMine(Jetbrains IDE)文件树的字体颜色?
- c++ - 关于 C++ 中文字定义的说明
- python - 无法使用虚拟环境在 Windows Ubuntu WSL 中启动 Scrapy 项目
- android - 如何克服 Jarsigner 报告“签名算法:MD5withRSA(弱)”
- javascript - 检测到可能的 EventEmitter 内存泄漏。不和谐.js
- python - 多线程:tkinter mainloop 不在主线程中
- javascript - 在我的 json 和 javascript 文件中找不到错误
- php - Yii2 连接到另一台服务器上 Docker 实例内的 MYSQL 数据库
- export-to-csv - DBeaver 导出为 CSV
- c++ - 我们可以通过排序左起点来解决逐点覆盖问题吗