I have a list of values meant to be parsed into a dropdown button with JSON from a rest API. Values are parsed fine and well but I applied a condition that when there is no list of values available to display then it should simply show a single text on the dropdown saying "no equipment". But for some reason, this is not working.
My code:
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,
),