Solved: flutter remove DropdownButton left padding

Question

Asked by Taufik N on December 08, 2021 (source).

I've struggled to remove flutter's DropdownButton left padding so it can match the TextField below. Anyone can help?

Here's my code:

DropdownButton<MenuModel>(
  itemHeight: itemHeight,
  isExpanded: true,
  underline: null,
  value: currentValue,
  hint: Text(placeholder, style: hintStyle),
  style: textStyle,
  disabledHint: Text(currentValue?.label ?? placeholder, style: textStyle),
  onChanged: widget.modalMode ? null : _onChanged,
  items: widget.listMenu.map<DropdownMenuItem<MenuModel>>((MenuModel val) {
    return DropdownMenuItem<MenuModel>(
      child: Text(val.label),
      value: val,
    );
  }).toList(),
)

enter image description here

Answer

Question answered by Taufik N (source).

finally I've found the problem. So it happen because I wrapped the DropdownButton with ButtonTheme(alignedDropdown: true)

ButtonTheme(
  alignedDropdown: true, // it's the culprit
  child: DropdownButton<MenuModel>(
    itemHeight: itemHeight,
    isExpanded: true,
    underline: null,
    value: currentValue,
    hint: Text(placeholder, style: hintStyle),
    style: textStyle,
    disabledHint: Text(currentValue?.label ?? placeholder, style: textStyle),
    onChanged: widget.modalMode ? null : _onChanged,
    items: widget.listMenu.map<DropdownMenuItem<MenuModel>>((MenuModel val) {
      return DropdownMenuItem<MenuModel>(
        child: Text(val.label),
        value: val,
      );
    }).toList(),
  ),
)

Thanks for the help.

FLUTTER FLUTTER-LAYOUT
SHARE: