I have this dropdown list and I want a few things changed, but have no clue how to do so.
- I want the width of the dropdown to equal the width of the container above. As you can see in the example I provided above, it is not equal and that looks really bad.
- There is way too much padding in the dropdown options right now. I need everything to be compressed to minimum padding so I can specify the padding I want
Here is my code for the Dropdown FormField, and here is a screenshot
Container(
width: size.width * .9,
child: DropdownButtonFormField2(
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Muscle',
filled: true,
isDense: true,
fillColor: Colors.white24,
hintStyle: TextStyle(color: Colors.green),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white),
),
),
style: TextStyle(color: Colors.black),
value: selectedMuscleGroup,
onChanged: (String? newValue) {
setState(() {
selectedMuscleGroup = newValue;
});
},
items: <String>[
'Biceps',
'Triceps',
'Chest',
'Back',
'Legs',
'Shoulders'
].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Container(
padding: EdgeInsets.zero, child: Text(value)),
);
}).toList(),
),
),
Thank you so much in advance!!
2
Answers
Wrap your
DropdownButtonFormField
in aButtonTheme
widget, and set thealignedDropdown: true
property of theButtonTheme
widget.DropdownButtonFormField2
provides flexible options to customize.To Manage Padding:
Overall dropdownPadding can be set via
dropdownStyleData
andSpecific menu padding can be set via
menuItemStyleData
To Control Width:
There is
width
property andoffset
to set overall width of dropdown padding and its position indropdownStyleData
.Example for your case,
Code:
Output: