i am a beginner of flutter.iam creating a DropdownButton to list the items.item was loading well on DropdownButton .but loading item selected not displayed at the DropdownButton i don't know. what i tried so far i attached below. what is the wrong here onChanged: (value) => setState(() => this.valueschoose = value,
DropdownButton<String>(
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (value) => setState(() => this.valueschoose = value,
)),
CodePudding user response:
you forget to use value
in the dropdown widget
String? dropdownvalue;
Widget build(BuildContext context) {
return DropdownButton<String>(
value: dropdownvalue, // here need to add value of dropdown
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (value) => setState(
() => dropdownvalue = value,
));
}
Visit for the completed code
CodePudding user response:
you are missing this value
of dropdown button
DropdownButton<String>(
value: this.valueschoose,
items: <String>['A', 'B', 'C', 'D'].map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (value) => setState(() => this.valueschoose = value,
)),