Full width DropdownButton with adjust dropdown arrow icon in Flutter

DartWidgetFlutter

Dart Problem Overview


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,
)

Dart Solutions


Solution 1 - Dart

Just adding isExpanded:true to the DropdownButton

  Widget example() {
    return new DropdownButton(
          isExpanded: true,
            items: [
              new DropdownMenuItem(child: new Text("Abc")),
              new DropdownMenuItem(child: new Text("Xyz")),
            ],
            hint: new Text("Select City"),
            onChanged: null
        );
  }

Solution 2 - Dart

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSandip PatelView Question on Stackoverflow
Solution 1 - DartPablo CegarraView Answer on Stackoverflow
Solution 2 - DartaqwertView Answer on Stackoverflow