How to change DropdownMenuItem's background color for selected item

173 Views Asked by At

I use DropdownButtonFormField. Is there a way to change background color of the selected DropdownMenuItem? Please see the attached screen.Selected Item has grey color

It's always gray.

I tried all the options of the DropdownButtonFormField, nothing works.

1

There are 1 best solutions below

0
Alex Krasnov On

Thanks to @raw-chicken. I checked the sources and found that DropdownButtonFormField uses InkWell. So the best way I found is to wrap DropdownButtonFormField with the Theme widget and set focusColor:

Theme(
  data: Theme.of(context).copyWith(
    focusColor: Colors.amber,
  ),
  child: DropdownButtonFormField<String>(
    value: 'Item 2',
    onChanged: (value) {},
    items: ['Item 1', 'Item 2', 'Item 3'].map((item) {
      return DropdownMenuItem<String>(
        value: item,
        child: Text(item),
      );
    }).toList(),
  ),
)