RenSword
RenSword

Reputation: 99

How to increase white space in between the text and the arrow in a DropdownButton in flutter?

DropdownButton(
  value: dropDownValue1,
  onChanged: (String? newValue) {
    setState(() {
      dropDownValue1 = newValue!;
    });
  },
  items: <String>[
    'Work At Office',
    'Work From Home',
  ].map<DropdownMenuItem<String>>((String value) {
    return DropdownMenuItem<String>(
      value: value,
      child: Text(value),
    );
  }).toList(),
)

how to increase space between the arrow and the text

Now

I hope I can make it be like this, how to do it?

Desired output

Thanks in advance

Upvotes: 2

Views: 2713

Answers (2)

Ravindra S. Patil
Ravindra S. Patil

Reputation: 14775

Try below code hope its helpful to you. refer my answer here also

Declare one variable for dropdown:

var dropdownValue = 'Work At Office';

Your widget

InputDecorator(
      decoration: const InputDecoration(border: OutlineInputBorder()),
      child: DropdownButtonHideUnderline(
        child: DropdownButton<String>(
          value: dropdownValue,
          isDense: true,
          isExpanded: true,
          onChanged: (String? newValue) {
            setState(() {
              dropdownValue = newValue!;
            });
          },
          items: <String>[
            'Work At Office',
            'Work From Home',
          ].map<DropdownMenuItem<String>>((String value) {
            return DropdownMenuItem<String>(
              value: value,
              child: Text(value),
            );
          }).toList(),
        ),
      ),
    ),

enter image description here

Upvotes: 2

Jahidul Islam
Jahidul Islam

Reputation: 12565

Just add isExpanded: true, under the dropdown for expanding icon

DropdownButton(
  isExpanded: true, // here need to change
  value: dropDownValue1,
  onChanged: (String? newValue) {
    setState(() {
      dropDownValue1 = newValue!;
    });
  },
  items: <String>[
    'Work At Office',
    'Work From Home',
  ].map<DropdownMenuItem<String>>((String value) {
    return DropdownMenuItem<String>(
      value: value,
      child: Text(value),
    );
  }).toList(),
)

Output:

enter image description here

Upvotes: 7

Related Questions