NduJay
NduJay

Reputation: 810

No way to customise padding on DropdownButtonFormField - Flutter

I am using the DropdownButtonFormField. It seems to have no way to customise the padding. With the TextFormField, if I set dense to true, I can customise the padding, etc. to make it the size I want. I set dense to true on the DropdownButtonFormField and nothing happens.

See screenshot below

enter image description here

Edit:

I can control the height with a container

enter image description here

but when there is an error, it shrinks in an extremely weird way, likely because the container wraps the whole dropdown button.

enter image description here

Upvotes: 1

Views: 1430

Answers (2)

harizh
harizh

Reputation: 386

In the input decoration property please add below codes and check. hope it works. counter text do the trick. also see the image below

filled: true, counterText: "", contentPadding: const EdgeInsets.symmetric(vertical: 25.0, horizontal: 20.0),

enter image description here

Upvotes: 0

harizh
harizh

Reputation: 386

Try my code pasted below. I think we can wrap it with container to customize the padding too. Please ignore the functionality onpress property.

Tooltip(
      message: "Maker dropdown",
      child: Container(
        padding: const EdgeInsets.only(left: 5.0),
        decoration: BoxDecoration(
          color: Theme.of(context).hoverColor,
          shape: BoxShape.rectangle,
          borderRadius: BorderRadius.circular(5),
        ),
        child: DropdownButtonHideUnderline(
            key: UniqueKey(),
            child: ButtonTheme(
                key: UniqueKey(),
                alignedDropdown: true,
                child: DropdownButtonFormField<Makers>(
                  key: UniqueKey(),
                  style: Theme.of(context).textTheme.headline2,
                  dropdownColor: Theme.of(context).backgroundColor,
                  decoration: InputDecoration(
                      icon:  FaIcon(
                        FontAwesomeIcons.screwdriverWrench,
                        color: Theme.of(context).hintColor,
                      ),
                      focusedBorder: const UnderlineInputBorder(
                          borderSide: BorderSide(color: Colors.transparent)),
                      enabledBorder: const UnderlineInputBorder(
                          borderSide: BorderSide(color: Colors.transparent)),
                      fillColor: Colors.transparent),
                  value: _myMaker,
                  iconSize: 15.0,
                  isExpanded: true,
                  icon: Icon(Icons.arrow_forward_ios,
                      color: Theme.of(context).hintColor),
                  elevation: 8,
                  hint: AutoSizeText("Select Maker",
                      style: Theme.of(context).textTheme.headline3),
                  onChanged: (Makers? newValue) {
                    setState(() {
                      _myMaker = newValue;
                    });
                  },
                  validator: (value) => Validator.validateMakers(
                    myMaker: _myMaker,
                  ),
                  items: items = _makersList
                      .map((item) => DropdownMenuItem<Makers>(
                    key: UniqueKey(),
                    value: item,
                    child: Text(item!.name),
                  ))
                      .toList(),
                ))),
      ),
    );

enter image description here

Upvotes: 1

Related Questions