Search code examples
flutterflutter-layoutdropdown

Dropdown button display text cut off Flutter


Hi I have a dropdown button whose hint and selected value text is cut off when too long:

It should be displaying "Department Code / Department Number"

enter image description here

Code:

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

    )
}

Any idea how to fix the display?


Solution

  • In the Container(), add in BoxConstraints and specify minHeight and maxHeight

    constraints: new BoxConstraints(
      minHeight: 50.0,
      maxHeight: 70.0,
    )