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
For those who are facing this problem in future. Use variable to set the value to DropdownButton and when the onChanged called update the variable using setState
Expanded(child: DropdownButton(
items: cities.map((String value) {
return DropdownMenuItem(
value: value,
child: Text(value),
);
}).toList(),
value: city,
onChanged: (String val) {
_onDropDownChanged(val);
},
),)
update the city variable by using state
void _onDropDownChanged(String val) {
setState(() {
this.city = val;
});
}
For further information check the link below
https://github.com/FazalHussain/Flutter-Demo/blob/trip_cost_app/lib/main.dart