Reputation: 2872
How can I highlight a selected item in the dropdown? Currently, when the dropdown items open up, the already selected item is not understandable.
Upvotes: 2
Views: 890
Reputation: 2171
You can use selectedItemBuilder
parameter in the DropdownButton
as follow:
DropdownButton<String>(
value: dropdownValue,
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
style: const TextStyle(color: Colors.blue),
selectedItemBuilder: (BuildContext context) {
return options.map((String value) {
return Text(
dropdownValue,
style: const TextStyle(color: Colors.white),
);
}).toList();
},
items: options.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
also, you can change the style of different options using items
parameter as is clear in the above example. For more info see this.
Upvotes: 2