I am trying to put a DropdownButton
on one of my screens. I have followed several examples but I can not get it to show the selected item. It keeps showing the first item in the list.
String _trxnStatus = 'Listed';
DropdownButton<String>(
hint: Text('Please choose transaction status'),
value: _trxnStatus,
onChanged: (value) {
setState(() {
_trxnStatus = value;
});
},
items: <String>['Listed', 'Under Contract', 'Closed'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
I have traced the value through the debugger. onChange
works fine and shows the selected value. However, when it comes to mapping the list and returning the DropdownMenuItem
the var value = 'Listed'
.
How do I get this to work? Thanks.