4

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
  • 1
    The only way I was able to replicate your issue was by giving a custom bounds to the Container which holds the dropdown. But the code you provided doesn't have any bounds. Try to give width and height to the Container and adjust them per your need to see the hint text render properly. Commented May 27, 2020 at 7:24
  • @Darshan hmm ya I didnt provide the entire scaffold layout as its too long. Okay i'll give it a try, thanks Commented May 27, 2020 at 7:36
  • Try with wrapping the text widget in horizontal listview with maxLine property of the text as 1. Commented May 27, 2020 at 20:55

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.