90

I needed to add DropdownButton with full width with adjust dropdown arrow icon in Flutter as well. But with many tried it in many ways but it doesn't expand its width full.

This is my code for DropdownButton:

new Expanded(
    child: new Column(
    children: <Widget>[
        new DropdownButton(
            items: [
                new DropdownMenuItem(child: new Text("Abc")),
                new DropdownMenuItem(child: new Text("Xyz")),
            ],
            hint: new Text("Select City"),
            onChanged: null
          )
       ]
    ),
    flex: 1,
)

2 Answers 2

284

Just adding isExpanded:true to the DropdownButton

  Widget example() {
    return DropdownButton(
          isExpanded: true,
            items: const [
               DropdownMenuItem(child: Text("Abc")),
               DropdownMenuItem(child: Text("Xyz")),
            ],
            hint: const Text("Select City"),
            onChanged: null
        );
  }
Sign up to request clarification or add additional context in comments.

2 Comments

Do not forget to add fix width container or expanded widget outside of DropDownButton widget otherwise "isExpanded: true" attribute will not work and show error in console. Thanks for asking query.
It makes sense, but I didn't test this variable because I assumed it meant the dropdown itself would be expanded/opened
3

Try to add the following in the Column you have...

Column(
  crossAxisAlignment: CrossAxisAlignment.stretch,
  ...
)

You should not need the Expanded widget as that would try to fill the vertical space and not the horizontal (width) space.

2 Comments

Thanks @aqwert using your code i got full width of DropdownButton but DropDownButton Arrow not Adjusted there. As full width of DropdownButton arrow should be positioned at end.
Adding isExpanded: true to the DropDownButton fixed this @SandipPatel

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.