Flutter:如何将DropdownButton菜单图标对齐到最右侧?

10

我需要将我的 flutter 应用程序中的 dropdown 对齐到最右边。它已经对齐了,但在我的实际应用程序中,我有多个一个接一个的 dropdowns。不同的下拉菜单项长度可能不相同。因此,我需要所有这些都对齐到最右边。

以下是我的代码。

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

我该如何做到这一点?

1个回答

23

DropdownButton中设置isExpanded:true

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接