我遇到的挑战与我读过的here类似:
但是,答案并不能解决问题。现在我被困住了。这是我的代码:
if (snapshot.hasData) {
List<String> zipCodes = List<String>.from(snapshot.data);
zipCodeValue = zipCodes[0];
return Center(
child: Container(
height: 50,
child: DropdownButton<String>(
items: zipCodes.map((String dropDownStringItem) {
return DropdownMenuItem<String>(
value: dropDownStringItem,
child: Text(dropDownStringItem),
);
}).toList(),
onChanged: (String newValueSelected) {
setState(() {
zipCodeValue = newValueSelected;
});
},
value: zipCodeValue,
),
),
);
}
我按照建议将DropdownButton小部件包装在容器中,但没有解决问题。
我尝试了Stackoverflow问题的其他答案,但没有解决我的问题。
任何帮助将不胜感激。
答案 0 :(得分:0)
结果是,我不能在列中包装DropDownButton。我相信挑战是:
When a Column has one or more Expanded or Flexible children, and is placed in another Column, or in a ListView, or in some other context that does not provide a maximum height constraint for the Column, you will get an exception at runtime saying that there are children with non-zero flex but the vertical constraints are unbounded.[As noted here][1]
在Flexible小部件中包装DropDownButton起作用了。