Repository navigation
Extra vertical padding surrounding DropdownButtonFormField when compared to TextField #60624
Description
This issue was original reported by @cassioseffrin in #46844 (comment)
@shihaohong take a look:
the 1st field (price) is a common TextField with OutlineInputBorder border;
the 2nd field (unit) is a DropdownButtonFormField with OutlineInputBorder border;
Even with isDense=true there is an extra padding (8 pixes in total: 4 on top, 4 on bottom) between the labelText and the widget that wraps the labelText and the Icon
in dropdown.dart line 1284 there is a method that calculates the height, the result is 24 if I set it to 16 the DropdownButtonFormField render the same height of the TextField, however I think it's not correct to set it as a constant. I can't figure out where this 8 pixels of extra padding were created.
Line 1284 of dropdown.dart.
double get _denseButtonHeight {
final double fontSize =
_textStyle.fontSize ?? Theme.of(context).textTheme.subtitle1.fontSize;
return math.max(fontSize, math.max(widget.iconSize, _kDenseButtonHeight));
}
I am in last stable release of Flutter (Channel stable, v1.17.4)
@HansMuller, I don't think it's related to #59196, in this case the Text height is exactly the same. I actually have made a correction in the widget dropdown.dart, just 1 line of code. May I could make a PR?
The problem is the icon size calculation, the resulting height is stretching all the DropdownButtonFormField: see the results, both components are now with exactly the same height.



Activity
HansMuller commentedon Jun 30, 2020
This may be due to the padding added to the icon buttons to ensure that their hit area is 48x48.
cassioseffrin commentedon Jul 1, 2020
I think the real problem is in InputDecoration, according with the flutter docs: If isOutline property of [border] is true then contentPaddding is EdgeInsets.fromLTRB(12, 20, 12, 12) when [isDense] is true and EdgeInsets.fromLTRB(12, 24, 12, 16) when [isDense] is false.
According with the docs the default padding for an InputDecoration with outline border and isDense equals to true must be EdgeInsets.fromLTRB(12, 20, 12, 12). For some reason it's not rendering.
If I set the contentPadding of InputDecoration to EdgeInsets.fromLTRB(12, 22, 12, 14), It's rendering with exactly the same height of an ordinary TextField with outline border, without any changes in dropdown.dart.
Here is the the reduced version of my DropdownButtonFormField wrapped in a StreamBuilder. I also use the isExpanded: true, and the Text with overflow TextOverflow.ellipsis, but these properties doesn't have any side effect, I have already tested without them.
shihaohong commentedon Jul 6, 2020
Reproducible sample:
shihaohong commentedon Jul 6, 2020
The real issue is as @HansMuller suggested -- For DropdownButtonFormField, the padding is applied around the Text and the Icon widgets. Since the Icon widget is taller than the text widget inDropdownButtonFormField, the outline for DropdownButtonFormField will look "taller" due to the presence of the icon.For the TextField, the padding is applied around only the text, but not the icon specified in
InputDecorator.suffixIcon. One simple way to observe this is to play around with the left/right padding on both widgets with debug painting on to see what I mean.One way we could fix this is to have the DropdownButtonFormField's contentPadding behave asTextField's does. That would be a breaking change, since the padding would be applied to the right of the selected value rather than to the right of theDropdownButtonicon itself.Edit: Actually, it seems to be from the
Containercalculation described above:When the icon is shorter than 24.0 pixels tall, what ends up happening is that the
heightbeing prescribed to theContainerthat wraps theRowthat contains the text and icon inDropdownButtonFormFieldends up being taller than the icon and the font in the default case, which is 24.0 (_kDenseButtonHeight). However, when the icon is taller, the icon then dictates the height of the overall container, which will never be shorter than it currently is, causingDropdownButtonFormFieldto be taller than expected.[-]Extra padding in TextFields with OutlineInputBorder[/-][+]Extra padding surrounding DropdownButtonFormField when compared to TextField[/+][-]Extra padding surrounding DropdownButtonFormField when compared to TextField[/-][+]Extra vertical padding surrounding DropdownButtonFormField when compared to TextField[/+]shihaohong commentedon Jul 6, 2020
In the meantime, the workaround is to apply lesser vertical padding to the decoration for DropdownButtonFormField, since there is no way to make the contents of
DropdownButtonFormFieldshorter than 24.0 without introducing a breaking change.To get the DropdownButtonFormField's height to exactly match TextField's (assuming no modifications to TextStyle to either TextField or DropdownButtonFormField), this is how you would do it:
These values would of course vary depending on the actual heights, etc.
shihaohong commentedon Jul 6, 2020
One solution could be to remove the usage of
_kDenseButtonHeightaltogether and rely on the font and icon heights in determining the height of theDropdownButtonFormField. However, this would still require the user to reduce the icon size forDropdownButtonFormFieldto get the same height asTextField, and the icon sizes will no longer match since TextField's suffixIcon is not surrounded by contentPadding for TextField, whereas the dropdown widget in DropdownButtonFormField is.cassioseffrin commentedon Jul 6, 2020
@shihaohong thks for yours concerns and sensitivity to reach exactly point that I am.
That was what I have done at #46844, after some tests I have realised another issue with this approach, which is: the hit area will be shorter (It will cause bad response to user) and plus it will get a side effect when a custom icon size is set.
I also have tried to place the arrow_down Icon in decoration as a suffixIcon like in TextField. But It's very difficult to achieve due to the fact that suffix and prefix Icons are placed in another widget (InputDecoration).
At the moment, I have end up customising the contentPadding. However it's take a lot of additional code in large forms with additional suffix command icons. But it's works!
markusaksli-nc commentedon Jul 20, 2020
Reproducible on the latest master
1.21.0-2.0.pre.66.flutter doctor -v
exaby73 commentedon Nov 15, 2022
This issue is still reproducible on
Master (3.6.0-3.0.pre.26). Updating labels to reflect the sameflutter-triage-bot commentedon Aug 19, 2024
This issue is missing a priority label. Please set a priority label when adding the
triaged-designlabel.nebkat commentedon Oct 8, 2025
This also affects

DropdownMenu:Easiest fix is:
or
Pixel perfect 😃