我正在尝试在颤动上构建多个依赖的下拉菜单。第二个依赖于第一个。这是我实现的下拉列表的代码。
Container(
child: new DropdownButton<String>(
underline: SizedBox(
height: 1,
),
hint: new Text("Select Faculty"),
value: facultyId,
items: faculty.map((item) {
return new DropdownMenuItem(
child: new Text(item['name']),
value: item['id'].toString(),
);
}).toList(),
onChanged: (faculty == null)
? null
: (String newValue) {
setState(() {
filteredbatch.clear();
facultyId = newValue;
for (var item in allbatch) {
if (item['facultyId'].toString() == newValue){
filteredbatch.add(item);
disableBatch = false;
}
}
});
print(facultyId);
},
),
),
Container(
child: new DropdownButton<String>(
underline: SizedBox(
height: 1,
),
disabledHint: new Text("Select Faculty First"),
hint: Text("Select Batch"),
value: batchId,
onChanged: disableBatch
? null
: (String newValue) {
setState(() {
batchId = newValue;
disableSection = false;
});
print(batchId);
},
items: filteredbatch.map((item) {
return DropdownMenuItem(
child: Text(item['name']),
value: item['id'].toString(),
);
}).toList()),
),
每当我从第一个下拉菜单中选择一个下拉菜单时,它就会启用第二个下拉菜单,并让我从该下拉菜单中选择一个项目。当我从第二个下拉列表中选择一个项目并返回更改第一个下拉列表时,它会抛出错误,表明下拉列表需要一个具有相应值的项目。找到 0 或 2 个。我在这里迷路了。我该如何解决这个错误?