skip to Main Content

I have a DropdownButton that when it’s open looks like this.

enter image description here

Is it possible to make it narrower to adjust to the text?

This is my DropdownButton:

      DropdownButton<dynamic>(
        value: state.locale.languageCode,
        items: [
          DropdownMenuItem(
            value: 'EN',
            child: SizedBox(
              child: Text(
                'EN',
              ),
            ),
          ),
          DropdownMenuItem(
            value: 'DE',
            child: SizedBox(
              child: Text(
                'DE',
              ),
            ),
          ),
        ],
        onChanged: (newValue) {
          dropdownCallback(newValue, state);
        },
        underline: DropdownButtonHideUnderline(child: Container()),
      ),

I have tried to wrap it in sized boxes, both the Button and Menu items, and it doesn’t work. I can’t find any parameters in the documentation to help me with it. Any ideas?

2

Answers


  1. Try to wrap your Dropdown with Container and Set width it hope its help to you

    Container(
          width: 25,
          child: DropdownButton<dynamic>(
            isExpanded: true,
            items: [
              DropdownMenuItem(
                value: 'EN',
                child: Text(
                  'EN',
                ),
              ),
              DropdownMenuItem(
                value: 'DE',
                child: Text(
                  'DE',
                ),
              ),
            ],
            onChanged: (newValue) {},
            underline: DropdownButtonHideUnderline(child: Container()),
          ),
        ),
    

    Result-> image

    Login or Signup to reply.
  2. You can Do like below.

     Container(
                width: 45,
                child:   DropdownButton<dynamic>(
                  value: "EN",
                  itemHeight: 50.0,
                  isExpanded: true,
                  items: [
                    DropdownMenuItem(
                      value: 'EN',
                      child: SizedBox(
                        child: Text(
                          'EN',
                        ),
                      ),
                    ),
                    DropdownMenuItem(
                      value: 'DE',
                      child: SizedBox(
                        child: Text(
                          'DE',
                        ),
                      ),
                    ),
                  ],
                  onChanged: (newValue) {
                    // dropdownCallback(newValue, state);
                  },
                  underline: DropdownButtonHideUnderline(child: Container()),
                  // },
                ) ,
              )
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search