4

I am trying to use dropdown, and want to have Colors.white for the selected text, and Colors.black54 for the text of drop down list. But when I tried to use color attribute and change it to White, it also change the color of drop down text.

DropdownButton<String>(
                    //this changed the color of both text, intial text as well dropdown text color
                    dropdownColor: Colors.white,
                    value: value,
                    style: TextStyle(color: Colors.white),
                    icon: CircleAvatar(
                      radius: 12,
                      backgroundColor: Colors.white,
                      child: Icon(Icons.arrow_drop_down),
                    ),
                    items: places.map((String value) {
                      return new DropdownMenuItem<String>(
                        value: value,
                        child: new Text(
                          value,
                         //I tried giving text style here , but same result 
                          style: TextStyle(color: Colors.white),
                        ),
                      );
                    }).toList(),
                    onChanged: (_) {
                      setState(() {
                        value = _;
                      });
                    },
                  )

Here is the picture of it.

enter image description here enter image description here

1 Answer 1

9

Okay I found the Solution using selectedItemBuilder attribute of dropdown

 final List<String> places = ['Delhi', 'Mumbai', 'Kerela', 'Agra'];

 DropdownButton<String>(
                    selectedItemBuilder: (_) {
                      return places
                          .map((e) => Container(
                                alignment: Alignment.center,
                                child: Text(
                                  e,
                                  style: TextStyle(color: Colors.white),
                                ),
                              ))
                          .toList();
                    },
                    value: value,
                    icon: CircleAvatar(
                      radius: 12,
                      backgroundColor: Colors.white,
                      child: Icon(Icons.arrow_drop_down),
                    ),
                    items: places.map((String value) {
                      return new DropdownMenuItem<String>(
                        value: value,
                        child: new Text(
                          value,
                          style: TextStyle(color: Colors.black54),
                        ),
                      );
                    }).toList(),
                    onChanged: (_) {
                      setState(() {
                        value = _;
                      });
                    },
                  )

Here is the result

enter image description here enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.