4

How can i make the text expand to it's content? I Tried this

child: DropdownButtonHideUnderline(
                                  child: DropdownButton<String>(
                                items: _currentCitySelected.area
                                    .map((String dropDownStringItem) {
                                  return DropdownMenuItem<String>(
                                    value: dropDownStringItem,
                                    child: Container(
                                        child: Text(
                                      dropDownStringItem,
                                      maxLines: 2,
//                                      overflow: TextOverflow.clip,
                                    )),
                                  );
                                }).toList(),
                                onChanged: (String newValueSelected) {
                                  setState(() {
                                    this._currentAreaSelected =
                                        newValueSelected;
                                  });
                                },
                                value: _currentAreaSelected,
                              ))

[enter image description here Text expands to content in drop down dialog content, but it does'nt works the same way in the main view. enter image description here

0

1 Answer 1

10

Set isExpanded property of DropdownButton to true

isExpanded: true

Like that:

DropdownButtonHideUnderline(
            child: DropdownButton<String>(
              isExpanded: true,
              items: [...]
Sign up to request clarification or add additional context in comments.

1 Comment

This does fix the wrap issue but causes another. Now, the DropdownButton takes the entire screen width. Is there any way to now shrink it? EDIT: Just needed to wrap the button in a Container with constraints: BoxConstraints(maxWidth: 300)

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.