Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes InputDecorator to work with textScaleFactor, fixes Material Design differences. #12595

Merged
merged 5 commits into from
Oct 19, 2017

Conversation

gspencergoog
Copy link
Contributor

@gspencergoog gspencergoog commented Oct 18, 2017

There were a number of differences with the Material Design spec, including
several different padding values and underline thickness. This corrects
that so that the decorator is in line with the Material Design spec now.

Also, the decorator properly handles changes to the textScaleFactor, where
before it would not re-layout when needed, painting the cursor and
underline incorrectly.

The decorator also now properly animates helper, error, and hint text when
the textScaleFactor or input decoration properties change.

Helper text is now properly displayed in dense mode, as the spec shows.
Before this change, it was never displayed in dense mode.

Fixes #12485

@@ -368,9 +368,13 @@ class InputDecorator extends StatelessWidget {
/// Defaults to false.
final bool isEmpty;

/// The widget below this widget in the tree.
/// The widget below this widget in the tree. Typically, this is an [EditableText] widget.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that's true. In fact, of the two (non-test) cases where we create an InputDecorator in our code base, neither uses EditableText here. One uses a RepaintBoundary that contains an EditableText, and the other uses a Row to do fancy stuff.

I think most people using this directly will be doing so because they want to create a widget that matches a text field but isn't one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, reverted.

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

This looks good, just a few minor comments.

_cardModels = new List<CardModel>.generate(
_cardModels.length,
(int i) {
_cardModels[i].height = _editable ? max(_cardHeights[i], 60.0) : _cardHeights[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this papering over the fact that we'll draw the textfield underline through the middle of the textfield if there isn't enough room?

Maybe we should draw the underline at all, if there isn't enough vertical. Maybe we should provide a constant (lib/src/material/constants.dart) like kMinTextFieldSize?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, we won't do that anymore, it'll just overflow, so it's not really papering over anything. I'm mainly fixing the demo here to not overflow. It does mean that the behavior has changed, but the old behavior was wrong.

If they are overflowing their container now, then they can either turn on "isDense" in the InputDecoration, or give the text field a InputDecoration.collapsed decoration.

The height of the text field can't be a constant, unfortunately. If it's multi-line or the textScaleFactor is >1.0, or the child of the decorator isn't a text field at all, then it'll be wrong.

@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math';
Copy link
Contributor

Choose a reason for hiding this comment

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

Glad to see that you've checked this old manual test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it's part of the Travis smoke tests, so it kind of had to be fixed...


double topPadding = isCollapsed ? 0.0 : (isDense ? 12.0 : 16.0);
double topPadding = isCollapsed ? 0.0 : 2.0 * (isDense ? _kDensePadding : _kNormalPadding);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's hard to understand why there's a factor of 2 here. Maybe add a comment where these constants are defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, I've added some new constants to document it better.


final double topPaddingIncrement = labelTextHeight + (isDense ? _kDensePadding : _kNormalPadding) - 4.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This another example of holding the changes to a higher standard than the original code: what's the -4 for here? I think it's comment-worthy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This turns out to be just a measurement error on my part: it's the height of the label descender (at the default font size), so I can just remove it here and below.

style: subtextStyle,
textAlign: textAlign,
overflow: TextOverflow.ellipsis,
final double linePadding = _kBottomBorderHeight + (isDense ? _kDensePadding : _kNormalPadding) - 4.0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same nit about -4.0 as above here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

errorText ?? helperText,
style: subtextStyle,
textAlign: textAlign,
overflow: TextOverflow.ellipsis,
Copy link
Contributor

Choose a reason for hiding this comment

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

NICE

@@ -52,4 +53,190 @@ void main() {

expect(tester.element(find.byKey(key)).size, equals(const Size(800.0, 60.0)));
});

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we have a test that verifies that the divider (the text underline) appears when it's supposed and that it appears in the correct place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Added.

…ign differences.

There were a number of differences with the Material Design spec, including
several different padding values and underline thickness.  This corrects
that so that the decorator is in line with the Material Design spec now.

Also, the decorator properly handles changes to the textScaleFactor, where
before it would not re-layout when needed, painting the cursor and
underline incorrectly.

The decorator also now properly animates helper, error, and hint text when
the textScaleFactor or input decoration properties change.
@HansMuller
Copy link
Contributor

LGTM

@gspencergoog gspencergoog merged commit 67cf791 into flutter:master Oct 19, 2017
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Oct 23, 2017
…rial Design differences. (flutter#12595)"

This reverts commit 67cf791.

Reverting because this causes scuba regressions that I'd like to
address in another PR that is pending, but we'd like to roll Flutter.
gspencergoog added a commit that referenced this pull request Oct 23, 2017
…rial Design differences. (#12595)" (#12678)

This reverts commit 67cf791.

Reverting because this causes scuba regressions that I'd like to
address in another PR that is pending, but we'd like to roll Flutter.
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request Oct 24, 2017
…xes Material Design differences. (flutter#12595)" (flutter#12678)"

This reverts commit 72dc7d9.

Re-landing my InputDecorator changes so that I can land the character counter PR.
gspencergoog added a commit that referenced this pull request Oct 24, 2017
…xes Material Design differences. (#12595)" (#12678)" (#12689)

This reverts commit 72dc7d9.

Re-landing my InputDecorator changes so that I can land the character counter PR.
@gspencergoog gspencergoog deleted the input_hint_pos branch February 12, 2018 18:11
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 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.

Hint text on TextField isn't positioned correctly when textScaleFactor is large
4 participants