11

I create a Flutter Form and I build a dropdown button with flutter. I am losing local son data into dropdown. Some of my items in dropdown button is long. I use SafeArea and ListView and I am getting overflow on right.

partial solution not mentioned in the other question, and I get the answer here.

Any idea how to fix it?

 // TODO: BUILD RUN
        return new Scaffold(
            key: _scaffoldKey,
            body: new SafeArea(
                top: false,
                bottom: false,
                child: new Form(
                    key: _formKey,
                    child: new ListView(
                      padding: const EdgeInsets.symmetric(
                          horizontal: 16.0, vertical: 32.0),
                      children: <Widget>[
                        //TODO: CURRENCY 
                        new FormField<String>(
                          builder: (FormFieldState<String> state) {
                            return InputDecorator(
                              decoration: InputDecoration(
                                labelText: 'CHOOSE CURRENCY',
                                labelStyle: TextStyle(
                                    fontSize: 18.0,
                                    fontWeight: FontWeight.bold,
                                    color: Colors.green.shade700),
                                errorText: state.hasError ? state.errorText : null,
                              ),
                              isEmpty: _mySelectedCurrency == '',
                              child: new DropdownButtonHideUnderline(
                                child: new DropdownButton<String>(
                                  style: TextStyle(
                                    fontSize: 14.0,
                                    color: Colors.black,
                                    fontWeight: FontWeight.w500,
                                  ),
                                  value: _mySelectedCurrency,
                                  isDense: true,
                                  onChanged: (String newValue) {
                                    setState(() {
                                      _mySelectedCurrency = newValue;
                                      state.didChange(newValue);
                                    });
                                  },
                                  items: _itemsName,
                                ),
                              ),
                            );
                          },
                          validator: (val) {
                            return val != '' ? null : 'Choose Currency...';
                          },
                        ),
                      ],
                    ))));
2
  • Possible duplicate of Flutter - DropdownButton overflow in ListView Commented Nov 8, 2018 at 17:47
  • yes its similar... And seems GitHub issues not resolved yet. Problem is that work around will not going to fix for me, the dropdown menu item will be more than 3 line sometimes... Looking for fixed and closed solution, thanks Commented Nov 8, 2018 at 17:56

2 Answers 2

53

Though I have flagged the question as possible duplicate, a partial solution not mentioned in the other question is to use the isExpanded property for DropDownButton.

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

4 Comments

Thanks, it's working without getting any error or overflow. But I need to ask. What do you mean "partial solution"?
Well, reading the last comment in the Github issue, I couldn't but agree with the poster. It works but may not work in all situations.
thanks, still looking final solution, and I modify my menu item so currently I have no problem...
also works on the DropdownButtonFormField
9

In most cases, in addition to the expanded, it is also good to make it ellipsized.. steps 1 and 2. If it's not ellipsized it will make it wrap to next line and if the component doesn't support multiples lines it will truncated the text.

DropdownButton(
    isExpanded: true, //Step 1
    items: [
        new DropdownMenuItem(
            child: Text("Long text that overflow the size.. wrapped or ellipsized", 
            overflow: TextOverflow.ellipsis),  //Step 2
        ),
    ],
    onChanged: (val) { }
)

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.