Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: How to align the DropdownButton menu icon to the far right?

I need to align the dropdown of my flutter application to the far right. It is already aligned, but in my real application I have multiple dropdowns one below another. The menu item length will not be similar in all dropdowns. So I need all of these aligned to the far right.

Below is my code.

Row(
  children: <Widget>[
    Expanded(
      flex: 1,
      child: Container(
        margin: EdgeInsets.only(left: 10),
        child: Text(
          "Size: ",
          style: Theme.of(context).textTheme.subhead,
        ),
      ),
    ),
    Expanded(
      flex: 3,
      child: DropdownButton(
        hint: Text(
          "Please Select          ",
          style: TextStyle(
            fontSize: 14,
          ),
        ),
        items: <String>[
          'Skinless Boneless, Full Loins',
          'brown',
          'silver'
        ].map((data) {
          return DropdownMenuItem(
            child: new Text(data,
                style: TextStyle(
                  fontSize: 14,
                )),
            value: data,
          );
        }).toList(),
        onChanged: (String newValue) {
          setState(() {
            _sizedropDown = newValue;
            print(newValue);
          });
        },
        value: _sizedropDown,
      ),
    )
  ],
)

How can I do this?

like image 986
PeakGen Avatar asked Jan 22 '20 08:01

PeakGen


1 Answers

Set isExpanded: true in DropdownButton,

Row(
  children: <Widget>[
    Expanded(
      flex: 1,
      child: Container(
        margin: EdgeInsets.only(left: 10),
        child: Text(
          "Size: ",
          style: Theme.of(context).textTheme.subhead,
        ),
      ),
    ),
    Expanded(
      flex: 3,
      child: DropdownButton<String>(
        isExpanded: true,
        hint: Text(
          "Please Select          ",
          style: TextStyle(
            fontSize: 14,
          ),
        ),
        items: <String>[
          'Skinless Boneless, Full Loins',
          'brown',
          'silver'
        ].map((data) {
          return DropdownMenuItem(
            child: new Text(data,
                style: TextStyle(
                  fontSize: 14,
                )),
            value: data,
          );
        }).toList(),
        onChanged: (String newValue) {
          setState(() {
            _sizedropDown = newValue;
            print(newValue);
          });
        },
        value: _sizedropDown,
      ),
    )
  ],
)
like image 117
Crazy Lazy Cat Avatar answered Nov 02 '22 05:11

Crazy Lazy Cat