Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 401
Huiting Avatar asked Nov 03 '25 12:11

Huiting


1 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

like image 71
chetan vallish Avatar answered Nov 06 '25 04:11

chetan vallish