2
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

Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
RenSword
  • 79
  • 8

2 Answers2

7

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

Jahidul Islam
  • 11,435
  • 3
  • 17
  • 38
1

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

Muhammad Hussain
  • 966
  • 4
  • 15
Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
  • thank you too, what does `InputDecoration(border: OutlineInputBorder()),` and `isDense: true` do – RenSword Nov 19 '21 at 07:18
  • 1
    @RenSword The `InputDecoration` is used for border, labels, icons, and styles of the text fields and other things and 'isDense' means it reduce or remove the button height. you can refer `InputDecoration` [here](https://api.flutter.dev/flutter/material/InputDecoration-class.html) and Dropdown `isDense` also [here](https://api.flutter.dev/flutter/material/DropdownButton-class.html) – Ravindra S. Patil Nov 19 '21 at 07:25