我有一个值列表,旨在使用来自 rest API 的 JSON 解析为下拉按钮。值解析得很好,但我应用了一个条件,即当没有可显示的值列表时,它应该在下拉列表中简单地显示一个文本,说“没有设备”。但由于某种原因,这不起作用。
我的代码:
List data = List();
Future<String> getSWData() async {
setState(() {
isLoading = true;
});
var res = await http
.get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
resBody = json.decode(res.body);
setState(() {
data = resBody;
isLoading = false;
});
return "Sucess";
}
child: DropdownButton(
hint: new Text(
"Select Equipment",
style: style,
),
style: style,
onChanged: (newVal) {
setState(() {
_mySelectionEquipment = newVal;
});
},
value: _mySelectionEquipment,
items: data.map((item) {
return new DropdownMenuItem(
child: Row(
children: <Widget>[
Text(item['EquipmentMake'] ??
"No Equipment Registered"),
SizedBox(
width: 5,
),
SizedBox(
width: 5,
),
Text(item['EquipmentModel'] ?? ""),
],
),
value: item['EquipmentID'].toString(),
);
}).toList(),
isExpanded: false,
),