Skip to content

Add minimum height and width box constraints to input decoration icons - #18480

Merged
jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:icon_size
Jun 16, 2018
Merged

jonahwilliams merged 8 commits into
flutter:masterfrom
jonahwilliams:icon_size

Conversation

@jonahwilliams

Copy link
Copy Markdown
Contributor

I've added a set of box constraints around both the prefix and suffix input decorations. This does change the visual appearance of the input field, since they appear to have more spacing between them and the outer border.

Fixes #16672

@HansMuller , is this a reasonable approach to take? I know that there is an issue filled currently to support arbitrary widgets in these decorations. I worry that if I try to remove some of the padding and we add support for that, a larger widget would end up touching the border of the text field.

data: new IconThemeData(
color: iconColor,
size: iconSize,
Widget prefixIcon;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the original syntax, 'final ... foo == null ? null : ..." is used consistently in this file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted

@HansMuller

Copy link
Copy Markdown
Contributor

Constraining the size of the prefix and suffix widgets seems reasonable to me if the overall layout isn't disturbed given text or icon values for the prefix/suffix.

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

@HansMuller The layout is slightly disturbed, see the screenshot I added on the edited original message. I could replace the constrained box with padding based on the icon size, and then remove the padding between the prefix/suffix icons and the border. I am not sure how well this will work if we allow arbitrary widgets here

@HansMuller

Copy link
Copy Markdown
Contributor

The demo just has the one suffix icon (password field) and it does appear to be noticeably adjusted inwards. On the other hand the MD spec now appears to accommodate a 48x48 icon:

screenshot from 2018-06-14 14-53-45

I think constraining the minimum sizes of the prefix and suffix widgets to 48x48 is OK.

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

Update: I've made the prefix/suffix icons responsible for padding by removing the L/R padding if they are defined. Their touch area is lined up exactly with the end of the text field, and there are 12 px between the start of the icon and the edge of the text field

flutter_06

@HansMuller

Copy link
Copy Markdown
Contributor

This looks good! Please add tests that verify the layout of prefix and suffix icons and update the doc to warn users that the prefix and suffix icon widgets will be constrained to be at least 48x48 and will be left or right justified. And the existing note/example about padding might not be useful anymore.

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

Updated doc comments and added test case

),
);

// Overall height for this InputDecorator is 48dps:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something is wrong here. The listed heights add up to 40 and the test checks for an overall height of 40, but the comment (and the point of this PR) say we're expecting an overall height of 48.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into it... might be drawing outside of bounds If I didn't correctly update something in the render object

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed locally that without a border the icons are drawn outside of bounds

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_RederDecoration.layout() should be taking the heights of the prefix and suffix icons into account when it computes containerHeight. It doesn't appear to be doing that - which would be an existing bug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to put too fine a point on it, but. I think this:

    double containerHeight = contentPadding.top
      + aboveBaseline
      + belowBaseline
      + contentPadding.bottom;

Should be:

    double containerHeight = contentPadding.top
      math.max(aboveBaseline + belowBaseline, math.max(_boxSize(prefixIcon.height), _boxSize(suffixIcon.height))),
      + contentPadding.bottom;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to take math.max over both prefix/suffix icons vs the baselines, since the don't have extra padding.

@jonahwilliams

Copy link
Copy Markdown
Contributor Author

On the method below, adding prefixIcon and suffixIcon cause the min intrinsic height to be calculated correctly as 48px.

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/input_decorator.dart#L900

However the RenderObject is also given tight constraints which might be incorrect.

https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/material/input_decorator.dart#L928

+ belowBaseline
+ contentPadding.bottom;
+ contentPadding.bottom,
math.max( _boxSize(suffixIcon).height, _boxSize(prefixIcon).height));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to formula discussed in chat

return contentPadding.top
+ (label == null ? 0.0 : decoration.floatingLabelHeight)
+ _lineHeight(width, <RenderBox>[prefix, input, suffix])
+ _lineHeight(width, <RenderBox>[prefix, prefixIcon, input, suffix])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right either. We should talk.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@HansMuller

Copy link
Copy Markdown
Contributor

LGTM

This PR also fixes a layout bug that had gone unnoticed because no test. NICE

@jonahwilliams
jonahwilliams merged commit 24a1f57 into flutter:master Jun 16, 2018
@jonahwilliams
jonahwilliams deleted the icon_size branch June 16, 2018 01:29
srawlins added a commit to srawlins/flutter that referenced this pull request Jun 16, 2018
* master:
  Add minimum height and width box constraints to input decoration icons (flutter#18480)
  Fix aot_snapshot_size_* benchmarks (flutter#18520)
  Revert "Remove race conditions involving finding available ports (flutter#18488)" (flutter#18521)
jonahwilliams pushed a commit that referenced this pull request Jun 16, 2018
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Textfield: touch target for prefixIcon/suffixIcon of InputDecoration is too small (should be 48dp, is 24dp)

3 participants