我在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']
如果我先单击列表2下拉列表,则会得到以下内容
Dropdown list 1 = ['two', 'three']
Dropdown list 2 = ['two', 'three', 'four']
我很困惑,并花了数小时,知道我可能做错了什么导致此刷新问题吗?
谢谢。