Skip to content

Conversation

@werainkhatri
Copy link
Member

@werainkhatri werainkhatri commented Sep 15, 2021

Added InputDecorator.floatingLabelAlignment to allow users to align the floating label left or center of the input field.

Fixes #27357
Design Doc

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.
@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Sep 15, 2021
@google-cla google-cla bot added the cla: yes label Sep 15, 2021
@skia-gold
Copy link

Gold has detected about 12 new digest(s) on patchset 2.
View them at https://flutter-gold.skia.org/cl/github/90157

@skia-gold
Copy link

Gold has detected about 8 new digest(s) on patchset 3.
View them at https://flutter-gold.skia.org/cl/github/90157

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Thanks for the great PR and design doc! I've left some comments on your design doc about the potential for some more fully-featured solutions to this problem. Let me know what you think.

@skia-gold
Copy link

Gold has detected about 14 new digest(s) on patchset 5.
View them at https://flutter-gold.skia.org/cl/github/90157

@justinmc
Copy link
Contributor

justinmc commented Oct 7, 2021

By the way, these are the issues that I think this PR might fix related to rounded borders: #82321 #28862

@justinmc
Copy link
Contributor

@werainkhatri Looks like there is a test failure on Linux web:

00:53 +164 ~1: test/material/input_decorator_test.dart: FloatingLabelAlignment.toString() ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following TestFailure object was thrown running a test: Expected: 'FloatingLabelAlignment(x: -1.0)' Actual: 'FloatingLabelAlignment(x: -1)' Which: is different. Expected: ... ment(x: -1.0) Actual: ... ment(x: -1) ^ Differ at offset 28 
Full error
00:53 +164 ~1: test/material/input_decorator_test.dart: FloatingLabelAlignment.toString() ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════ The following TestFailure object was thrown running a test: Expected: 'FloatingLabelAlignment(x: -1.0)' Actual: 'FloatingLabelAlignment(x: -1)' Which: is different. Expected: ... ment(x: -1.0) Actual: ... ment(x: -1) ^ Differ at offset 28 When the exception was thrown, this was the stack: ../dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_ ../packages/test_api/src/expect/async_matcher.dart.js 145:22 fail ../packages/test_api/src/expect/async_matcher.dart.js 142:12 _expect ../packages/test_api/src/expect/async_matcher.dart.js 75:12 expect$ ../packages/flutter_test/src/deprecated.dart.js 6684:12 expect$ input_decorator_test.dart.js 13672:21 <fn> ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async input_decorator_test.dart.js 13671:92 <fn> ../packages/flutter_test/src/deprecated.dart.js 6647:19 <fn> ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50 <fn> ../packages/stack_trace/src/stack_zone_specification.dart.js 160:98 <fn> ../packages/stack_trace/src/stack_zone_specification.dart.js 212:16 [_run] ../packages/stack_trace/src/stack_zone_specification.dart.js 160:80 <fn> ../dart-sdk/lib/async/zone.dart 1436:47 _rootRunUnary ../dart-sdk/lib/async/zone.dart 1335:19 runUnary ../dart-sdk/lib/async/future_impl.dart 160:18 handleValue ../dart-sdk/lib/async/future_impl.dart 767:44 handleValueCallback ../dart-sdk/lib/async/future_impl.dart 796:13 _propagateToListeners ../dart-sdk/lib/async/future_impl.dart 602:5 [_completeWithValue] ../dart-sdk/lib/async/future_impl.dart 640:7 <fn> ../packages/fake_async/fake_async.dart.js 123:40 flushMicrotasks ../packages/flutter_test/src/deprecated.dart.js 5469:19 <fn> ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54 runBody ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5 _async ../packages/flutter_test/src/deprecated.dart.js 5466:62 <fn> ../dart-sdk/lib/async/future.dart 276:37 <fn> ../packages/stack_trace/src/stack_zone_specification.dart.js 212:16 [_run] ../packages/stack_trace/src/stack_zone_specification.dart.js 155:71 <fn> ../dart-sdk/lib/async/zone.dart 1420:47 _rootRun ../dart-sdk/lib/async/zone.dart 1328:19 run ../dart-sdk/lib/async/zone.dart 1236:7 runGuarded ../dart-sdk/lib/async/zone.dart 1276:23 <fn> ../packages/stack_trace/src/stack_zone_specification.dart.js 212:16 [_run] ../packages/stack_trace/src/stack_zone_specification.dart.js 155:71 <fn> ../dart-sdk/lib/async/zone.dart 1428:13 _rootRun ../dart-sdk/lib/async/zone.dart 1328:19 run ../dart-sdk/lib/async/zone.dart 1236:7 runGuarded ../dart-sdk/lib/async/zone.dart 1276:23 callback ../dart-sdk/lib/async/schedule_microtask.dart 40:11 _microtaskLoop ../dart-sdk/lib/async/schedule_microtask.dart 49:5 _startMicrotaskLoop ../dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15 <fn> The test description was: FloatingLabelAlignment.toString() ════════════════════════════════════════════════════════════════════════════════════════════════════ 00:53 +164 ~1 -1: test/material/input_decorator_test.dart: FloatingLabelAlignment.toString() [E] Test failed. See exception logs above. The test description was: FloatingLabelAlignment.toString() 
@skia-gold
Copy link

Gold has detected about 12 new digest(s) on patchset 6.
View them at https://flutter-gold.skia.org/cl/github/90157

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #90157 at sha 0496a1f24bf0cc83be6ff6247e8a6692a89210bc

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Oct 12, 2021
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some questions and some smaller changes for you. I think overall this approach looks pretty nice to me. I need to check out your branch and play around with it myself still, will do that soon.

@skia-gold
Copy link

Gold has detected about 16 new digest(s) on patchset 7.
View them at https://flutter-gold.skia.org/cl/github/90157

@skia-gold
Copy link

Gold has detected about 8 new digest(s) on patchset 8.
View them at https://flutter-gold.skia.org/cl/github/90157

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #90157 at sha f7f4b97e64c5a63f43c185535be97da0ea102630

@werainkhatri werainkhatri requested a review from justinmc October 16, 2021 17:29
@mat100payette
Copy link

By the way, these are the issues that I think this PR might fix related to rounded borders: #82321 #28862

Has this been verified, or we just hoping it does ?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

I tried running this on my own machine and it seems to work great.

The only major thing that I think we should change is that the x calculation should be done based on arbitrary FloatingLabelBehavior.x, not just by checking for center, even though it's not supported for now. See my comment about that and let me know what you think.

Otherwise most of my comments are small nits. Thanks for being patient with this PR and sorry it took me so long to try this out!

Copy link
Contributor

Choose a reason for hiding this comment

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

Good catch.

@justinmc
Copy link
Contributor

justinmc commented Nov 1, 2021

@mat100payette Here's what the border from #82321 looks like when the label is centered:

floating_label

The fade in/out of the border under the label is a little weird, but otherwise it looks pretty good. I've left a comment in that issue to discuss allowing arbitrary x values or not.

@werainkhatri werainkhatri force-pushed the center-floating-label branch from f7f4b97 to 9fe11db Compare November 2, 2021 06:36
@skia-gold
Copy link

Gold has detected about 2 new digest(s) on patchset 9.
View them at https://flutter-gold.skia.org/cl/github/90157

@skia-gold
Copy link

Gold has detected about 8 new digest(s) on patchset 10.
View them at https://flutter-gold.skia.org/cl/github/90157

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #90157 at sha 1c338fc

@werainkhatri werainkhatri requested a review from justinmc November 2, 2021 07:28
@justinmc
Copy link
Contributor

justinmc commented Nov 2, 2021

It seems like arbitrary values for FloatingLabelAlignment would not help with rounded rects according to #82321 (comment), so that's another reason to leave that out of this PR for now and just use left and center.

@werainkhatri
Copy link
Member Author

It seems like arbitrary values for FloatingLabelAlignment would not help with rounded rects according to #82321 (comment), so that's another reason to leave that out of this PR for now and just use left and center.

Fair enough. I have made the default constructor for FloatingLabelAlignment private anyway. Do take a look at my replies to unresolved conversations above.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Thanks for handling the RTL stuff. I noticed one case where the docs need to be clarify left/right, otherwise just a few nits.

if (label != null) {
final Offset labelOffset = _boxParentData(label!).offset;
final double labelHeight = label!.size.height;
final double labelHeight = _boxSize(label).height;
Copy link
Contributor

Choose a reason for hiding this comment

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

Good call switching to _boxSize.

@werainkhatri
Copy link
Member Author

Should I make FloatingLabelAlignment.x private?

@justinmc
Copy link
Contributor

Yes that's a good idea, you should make it private. Just in case in the future if we change how it works under the hood for some reason, it definitely won't be a breaking change if x is private.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍

CC @LongCatIsLooong for secondary review.

if (label != null) {
final double labelX = _boxParentData(label!).offset.dx;
// +1 shifts the range of x from (-1.0, 1.0) to (0.0, 2.0).
final double floatAlign = decoration.floatingLabelAlignment._x + 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for making the calculations work with any _x and not just center and left 👍

@justinmc
Copy link
Contributor

No secondary review needed actually, I'll go ahead and merge this. Thanks for the PR!

@justinmc justinmc merged commit f62a128 into flutter:master Nov 23, 2021
@werainkhatri werainkhatri deleted the center-floating-label branch September 8, 2022 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

4 participants