Flutter:如何最小化 DropdownButton 的宽度

Jov*_*ski 9 flutter flutter-layout

DropdownButton在颤振基础上设置最大的宽度DropdownMenuItem从它的项目。如果选择了一个小项目,这会在项目和箭头之间留下大量空白。如何使按钮缩放以适合所选项目的宽度?

我尝试使用Expanded, 一些Flexible东西,但我仍然无法改变它的宽度。

DropdownButton(
    value: null,
    hint: Text("Small text"),
    items: ..., //Text widgets that have more text and are larger than the hint
)
Run Code Online (Sandbox Code Playgroud)

我试图摆脱hint和箭头之间带下划线的空间: 在此处输入图片说明

Luc*_*tos 0

这有效:

new Container(
            padding: const EdgeInsets.fromLTRB(10.0, 5, 10, 0),
            child: new Container(
              padding: const EdgeInsets.fromLTRB(10, 5, 5, 5),
              decoration: new BoxDecoration(
                  color: Colors.white,
                  borderRadius: new BorderRadius.only(
                      topLeft: const Radius.circular(5.0),
                      bottomLeft: const Radius.circular(5.0),
                      bottomRight: const Radius.circular(5.0),
                      topRight: const Radius.circular(5.0))),
              child: new Center(
                  child: new Column(children: [
                new DropdownButton(
                  underline: Text(''),
                  icon: Icon(Icons.keyboard_arrow_down),
                  hint: new Text('Small text'),
                  style: TextStyle(
                    color: Colors.white30,
                  ),
                  isExpanded: true,
                  value: _selectedLocation,
                  onChanged: (String newValue) {
                    setState(() {
                      _selectedLocation = newValue;
                    });
                  },
                  items: _locations.map((String location) {
                    return new DropdownMenuItem<String>(
                      value: location,
                      child: new Text(
                        location,
                        style: TextStyle(
                            color: myColour, fontWeight: FontWeight.bold),
                      ),
                    );
                  }).toList(),
                ),
              ])),
            ))
Run Code Online (Sandbox Code Playgroud)