I\' m gettings items from JSON and displaying them in a dropdown. When the person select an item from the dropdown list, I get the selection but the selected item doesn\'t c
You hard-coded the first city as value for the dropdown.
new DropdownButton(
value: cities.elementAt(0), //this one
...
You need to have some state
variable to hold the selected city.
class YourStatefulWidgetState extends State {
@override
initState() {
super.initState();
selectedCity = cities.elementAt(0)
}
@override
Widget build(BuildContext context) {
...
new DropdownButton(
value: selectedCity,
hint: new Text("Ville"),
items: cities.map((String value) {
return new DropdownMenuItem(value: value,
child: new Row(
children: [
new Icon(
Icons.location_city, color: Colors.deepOrange,),
new Text(value)
],
),);
}).toList(),
onChanged: (String value) {
setState(() {
selectedCity = getTravelCity(value);
});
},),
...