我又遇到了 DropdownButton 的另一个问题。
DropdownButton 未启用。我在 api.flutter.dev 中找到了这个
如果 onChanged 回调为 null 或项目列表为 null,则下拉按钮将被禁用,即其箭头将显示为灰色并且不会响应输入。
这是我现在的代码:
return new DropdownButton<String>(
hint: new Text("Select Agency"),
value: _currentAgency,
onChanged: changedDropDownAgency,
items: snapshot.data.docs.forEach((document) {
return new DropdownMenuItem<String>(
value: document.data()['name'],
child: new Text(document.data()['name']),
);
}),
);
void changedDropDownAgency(String selected_agency) {
setState(() {
_currentAgency = selected_agency;
});
globals.selectedAgency = selected_agency;
}
forEach 循环运行良好,在调试模式下我可以看到文档对象中有数据。我不知道如何调试 DropdownButton 代码以查看按钮未激活的原因。任何的意见都将会有帮助。谢谢。