下拉按钮显示的文本已切断Flutter

问题描述 投票:0回答:3

嗨,我有一个下拉按钮,其提示和所选值文本过长会被截断:

它应该显示“部门代码/部门编号”

enter image description here

代码:

DropdownButton<String> dropdownList(BuildContext context) {
  return new DropdownButton<String>(
    hint: new Text(
      "Department Code / Department Number", 
    ),
    value: selectedDept,
    isDense: true,
    onChanged: (String newValue) {
      //...
    },
    items: _item.map((Dept map) {
      return new DropdownMenuItem<String>(
        value: map.code,
        child:
            new Text(map.code, style: new TextStyle(color: Colors.black)),
      );
    }).toList(),
    isExpanded: true,
  );
}


 Widget build(BuildContext context) {
    return Scaffold(
        child: Column(
            children: <Widget>[
                Container(
                  padding: EdgeInsets.fromLTRB(
                      20, 20, 10, 20),
                  decoration: ShapeDecoration(
                    shape: RoundedRectangleBorder(
                      side: BorderSide(
                          width: 1.0,
                          style: BorderStyle.solid,
                          color: Colors.grey[400]),
                      borderRadius:
                          BorderRadius.all(
                              Radius.circular(
                                  15.0)),
                    ),
                  ),
                  child:
                      DropdownButtonHideUnderline(
                          child: dropdownList(
                              context)),
                )
            ]
        )

    )
}

任何想法如何固定显示器?

flutter flutter-layout dropdown
3个回答
0
投票

从文档Text widget documentation中,您可以试用overflowsoftWrapmaxLines属性。


0
投票

只需添加填充以在内部内容之间留出空间。

 return DropdownMenuItem<String>(
                        value: value,
                        child: Padding(
                          padding: EdgeInsets.all(4),
                          child: Text(map.code, style: new TextStyle(color: Colors.black)),
                        ),
                      );

0
投票

在Container()中,添加BoxConstraints并指定minHeight和maxHeight

constraints: new BoxConstraints(
  minHeight: 50.0,
  maxHeight: 70.0,
)
© www.soinside.com 2019 - 2024. All rights reserved.