87

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

267

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
        );
  }
2
  • 5
    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.
    – Kamlesh
    Feb 5, 2021 at 8:30
  • It makes sense, but I didn't test this variable because I assumed it meant the dropdown itself would be expanded/opened
    – mauriii
    Jul 5, 2022 at 17:28
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
  • 3
    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. Aug 15, 2018 at 4:54
  • 5
    Adding isExpanded: true to the DropDownButton fixed this @SandipPatel
    – Boy
    Feb 4, 2020 at 14:59

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.