-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix TextField intrinsic width when hint is not visible #161235
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
Fix TextField intrinsic width when hint is not visible #161235
Conversation
0e1aa4e to
9d4aff6
Compare
nate-thegrate
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, looks like a fantastic improvement overall.
a1e52c1 to
bbf2a79
Compare
nate-thegrate
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for the fix!
bbf2a79 to
f356db5
Compare
|
@justinmc When you have some bandwidth, thank you for having a look at these Google testing failures. This PR changes the default intrinsic width computation (ignoring the hint width when the field is not empty). Maybe we should consider introducing a new property to control this behavior? |
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good, minus the Google failures. I see three categories of failures:
- Expected visual diff changes where a field becomes less wide.
- Unexpected visual diff changes in the vertical size of a field.
- Unexpected changes in a displayed value in some tests (maybe caused by a misclick due to layout problems from the previous point).
I think I can reproduce the problem from point 2:
Example code
import 'package:flutter/material.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Material App',
home: Scaffold(
body: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 100.0),
child: const IntrinsicWidth(
child: TextField(
maxLines: null,
decoration: InputDecoration(
filled: true,
hintText: 'Moderately long hint text',
),
),
),
),
),
),
);
}
}Screen.Recording.2025-01-15.at.2.53.55.PM.mov
c0efcca to
9fd2320
Compare
|
I updated the PR to fix the failure related to point 2 (see #161235 (review)). As mentioned in #161235 (comment), adding a property to control the behavior is probably safer. Maybe we should deprecate this parameter and create a similar one that would also apply to the width? Such as maintainHintSize? |
|
Yeah I think I agree with the idea of adding a parameter. The difference is big enough to warrant one, and I do imagine some people might still prefer the old way. With a parameter, do you plan for it to work like it was when I reviewed it above? With the current state of the PR, it seems like it might affect the height of normal fields too, by looking at the failing Google tests. |
f1576ff to
e2db406
Compare
No because the height issue was bad I updated the PR to demonstrate what this parameter solution could be. |
e00eba9 to
a7cb8c1
Compare
nate-thegrate
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with 1 small nit. Thanks again for doing this!
a7cb8c1 to
f01d087
Compare
justinmc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍. All comments are nits. I tried it out and it works great. I definitely agree that adding the parameter is the right move.
| if (hintMaxLines != null) 'hintMaxLines: "$hintMaxLines"', | ||
| if (hintFadeDuration != null) 'hintFadeDuration: "$hintFadeDuration"', | ||
| if (!maintainHintHeight) 'maintainHintHeight: false', | ||
| if (!maintainHintSize) 'maintainHintSize: false', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the false be $maintainHintSize? I'm not sure why maintainHintHeight is hardcoded false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! I checked and the reason is that this toString implementation was designed to only output fields that don't use their default value. This pattern (hardcoding the non-default boolean value) was introduced in the early days, see #9119. I think it is ok to keep it as-is for this PR and we might decide to change the whole toString at one point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, thanks for the investigation!
f01d087 to
ef1f7e7
Compare
Manual roll requested by [email protected] flutter/flutter@c1561a4...c1ffaa9 2025-01-24 [email protected] Fix link to hotfix documentation best practices (flutter/flutter#162116) 2025-01-24 [email protected] Add integration test for cutout rotation evaluation (flutter/flutter#160354) 2025-01-24 [email protected] Reland "[Impeller] Migrate unit tests off of Skia geometry classes (#161855)" (flutter/flutter#162146) 2025-01-24 [email protected] Fix TextField intrinsic width when hint is not visible (flutter/flutter#161235) 2025-01-24 [email protected] When parsing flavors, handle Xcode build configurations that are not lowercase (flutter/flutter#161455) 2025-01-24 [email protected] [Impeller] Fix source offset in PathBuilder::AddPath (flutter/flutter#162052) 2025-01-24 [email protected] Add to Setup Path Example to Engine README (flutter/flutter#162115) 2025-01-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Unskip test. (#162106)" (flutter/flutter#162122) 2025-01-23 [email protected] feat: Add `hint` (Widget) property to InputDecoration (flutter/flutter#161424) 2025-01-23 [email protected] Fix skwasm target in wasm_debug_unopt build. (flutter/flutter#162100) 2025-01-23 [email protected] Marks Linux_android_emu android views to be unflaky (flutter/flutter#160493) 2025-01-23 [email protected] Unskip test. (flutter/flutter#162106) 2025-01-23 [email protected] Add ability to maintain bottom view padding in `NavigationBar` safe area (flutter/flutter#162076) 2025-01-23 [email protected] Roll pub packages (flutter/flutter#162095) 2025-01-23 [email protected] Delete an unused (manual) workflow, added missing copyright headers. (flutter/flutter#162050) 2025-01-23 [email protected] Android templates: update default Kotlin from 1.8.22 to 2.1.0, update default Gradle from 8.9 to 8.12 (flutter/flutter#160974) 2025-01-23 [email protected] flutter_tools: flutter_tester is a host artifact (flutter/flutter#162047) 2025-01-23 [email protected] [Impeller] Make glIsTexture mockable for use by the ReactorGLES.NameUntrackedHandle test (flutter/flutter#162082) 2025-01-23 [email protected] Remove "Mac Designed for iPad" as a discoverable `flutter run` device (flutter/flutter#161459) 2025-01-23 [email protected] Show error on macOS if missing Local Network permissions (flutter/flutter#161846) 2025-01-23 [email protected] Autocomplete keyboard navigation (flutter/flutter#159455) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
|
Is this fixed bug works with CupertinoTextField ? I've tried and it seems not working, maybe I'm doing it wrong... const IntrinsicWidth( |
|
@TiberioZ |
## Description This PR adds a dart fix to migrate from InputDecoration.maintainHintHeight to InputDecoration.maintainHintSize. ## Related PR Follow up to #161235 ## Tests Adds 1 test.
…11742) This PR adds a migration guide for inputDecoration.maintainHintHeight. Related PRs: - flutter/flutter#161235 - dart fix: flutter/flutter#162600 ## Presubmit checklist - [ ] This PR is marked as draft with an explanation if not meant to land until a future stable release. - [X] This PR doesn’t contain automatically generated corrections (Grammarly or similar). - [X] This PR follows the [Google Developer Documentation Style Guidelines](https://developers.google.com/style) — for example, it doesn’t use _i.e._ or _e.g._, and it avoids _I_ and _we_ (first person). - [X] This PR uses [semantic line breaks](https://github.com/dart-lang/site-shared/blob/main/doc/writing-for-dart-and-flutter-websites.md#semantic-line-breaks) of 80 characters or fewer.
) Manual roll requested by [email protected] flutter/flutter@c1561a4...c1ffaa9 2025-01-24 [email protected] Fix link to hotfix documentation best practices (flutter/flutter#162116) 2025-01-24 [email protected] Add integration test for cutout rotation evaluation (flutter/flutter#160354) 2025-01-24 [email protected] Reland "[Impeller] Migrate unit tests off of Skia geometry classes (#161855)" (flutter/flutter#162146) 2025-01-24 [email protected] Fix TextField intrinsic width when hint is not visible (flutter/flutter#161235) 2025-01-24 [email protected] When parsing flavors, handle Xcode build configurations that are not lowercase (flutter/flutter#161455) 2025-01-24 [email protected] [Impeller] Fix source offset in PathBuilder::AddPath (flutter/flutter#162052) 2025-01-24 [email protected] Add to Setup Path Example to Engine README (flutter/flutter#162115) 2025-01-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Unskip test. (#162106)" (flutter/flutter#162122) 2025-01-23 [email protected] feat: Add `hint` (Widget) property to InputDecoration (flutter/flutter#161424) 2025-01-23 [email protected] Fix skwasm target in wasm_debug_unopt build. (flutter/flutter#162100) 2025-01-23 [email protected] Marks Linux_android_emu android views to be unflaky (flutter/flutter#160493) 2025-01-23 [email protected] Unskip test. (flutter/flutter#162106) 2025-01-23 [email protected] Add ability to maintain bottom view padding in `NavigationBar` safe area (flutter/flutter#162076) 2025-01-23 [email protected] Roll pub packages (flutter/flutter#162095) 2025-01-23 [email protected] Delete an unused (manual) workflow, added missing copyright headers. (flutter/flutter#162050) 2025-01-23 [email protected] Android templates: update default Kotlin from 1.8.22 to 2.1.0, update default Gradle from 8.9 to 8.12 (flutter/flutter#160974) 2025-01-23 [email protected] flutter_tools: flutter_tester is a host artifact (flutter/flutter#162047) 2025-01-23 [email protected] [Impeller] Make glIsTexture mockable for use by the ReactorGLES.NameUntrackedHandle test (flutter/flutter#162082) 2025-01-23 [email protected] Remove "Mac Designed for iPad" as a discoverable `flutter run` device (flutter/flutter#161459) 2025-01-23 [email protected] Show error on macOS if missing Local Network permissions (flutter/flutter#161846) 2025-01-23 [email protected] Autocomplete keyboard navigation (flutter/flutter#159455) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
) Manual roll requested by [email protected] flutter/flutter@c1561a4...c1ffaa9 2025-01-24 [email protected] Fix link to hotfix documentation best practices (flutter/flutter#162116) 2025-01-24 [email protected] Add integration test for cutout rotation evaluation (flutter/flutter#160354) 2025-01-24 [email protected] Reland "[Impeller] Migrate unit tests off of Skia geometry classes (#161855)" (flutter/flutter#162146) 2025-01-24 [email protected] Fix TextField intrinsic width when hint is not visible (flutter/flutter#161235) 2025-01-24 [email protected] When parsing flavors, handle Xcode build configurations that are not lowercase (flutter/flutter#161455) 2025-01-24 [email protected] [Impeller] Fix source offset in PathBuilder::AddPath (flutter/flutter#162052) 2025-01-24 [email protected] Add to Setup Path Example to Engine README (flutter/flutter#162115) 2025-01-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Unskip test. (#162106)" (flutter/flutter#162122) 2025-01-23 [email protected] feat: Add `hint` (Widget) property to InputDecoration (flutter/flutter#161424) 2025-01-23 [email protected] Fix skwasm target in wasm_debug_unopt build. (flutter/flutter#162100) 2025-01-23 [email protected] Marks Linux_android_emu android views to be unflaky (flutter/flutter#160493) 2025-01-23 [email protected] Unskip test. (flutter/flutter#162106) 2025-01-23 [email protected] Add ability to maintain bottom view padding in `NavigationBar` safe area (flutter/flutter#162076) 2025-01-23 [email protected] Roll pub packages (flutter/flutter#162095) 2025-01-23 [email protected] Delete an unused (manual) workflow, added missing copyright headers. (flutter/flutter#162050) 2025-01-23 [email protected] Android templates: update default Kotlin from 1.8.22 to 2.1.0, update default Gradle from 8.9 to 8.12 (flutter/flutter#160974) 2025-01-23 [email protected] flutter_tools: flutter_tester is a host artifact (flutter/flutter#162047) 2025-01-23 [email protected] [Impeller] Make glIsTexture mockable for use by the ReactorGLES.NameUntrackedHandle test (flutter/flutter#162082) 2025-01-23 [email protected] Remove "Mac Designed for iPad" as a discoverable `flutter run` device (flutter/flutter#161459) 2025-01-23 [email protected] Show error on macOS if missing Local Network permissions (flutter/flutter#161846) 2025-01-23 [email protected] Autocomplete keyboard navigation (flutter/flutter#159455) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Description
This PR changes the TextField intrinsic width computation for non-empty TextField.
Before:
When a TextField is non-empty, the intrinsic width can't be smaller than the hint width:
After:
The width does not depend on the hint when the TextField is non empty.
Code sample
Related Issue
Fixes [TextField] The computation of the intrinsic width of a TextField should include the hint width only when visible
Tests
Adds 2 tests.