Dropdown button display text cut off Flutter

Viewed 1702

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?

3 Answers

If you dont want to increase the size of the dropdown, Change the content padding to something that suits you.

DropdownButtonFormField(
        itemHeight: 50,
        decoration: InputDecoration(
            contentPadding:
                EdgeInsets.symmetric(vertical: 5, horizontal: 10),
           .
           .
           .

Theres usually a default value for contentPadding which is cutting up your text. To access input decoration you'll need to use DropdownButtonFromField

Just add padding to make space between your inner content.

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

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

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