Skip to content

Conversation

@zeqinjie
Copy link
Contributor

This PR changes the Hint uses topLeft alignment when maintainHintSize is false

code

buildTextField() {
  return const Center(
    child: TextField(
      decoration: InputDecoration(
        hintText: 'hint',
        maintainHintSize: false,
      ),
    ),
  );
}

Before:

b

After:
a

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 this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on [Discord].

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels May 12, 2025
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 fixing, I agree this is a problem. Is there an issue about this that you know of?

Heads up that you have an analyzer failure.


final Stack stack = tester.widget<Stack>(stackFinder);
expect(stack.alignment, Alignment.topLeft);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you check the actual left position of the hintText too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justinmc Thanks you, I updated

Copy link
Contributor

@bleroux bleroux Jun 23, 2025

Choose a reason for hiding this comment

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

I proposed to simplify this test by checking if the hint position changes for maintainHintSize: false compared to maintaintHintSize: true.
That way the tests are simpler and does not depend on implementations details (AnimatedSwitcher and its Stack).

    testWidgets('Hint does not change position when maintainHintSize is false - LTR', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        buildInputDecorator(isEmpty: true, decoration: const InputDecoration(hintText: hintText)),
      );
      final double expectedHintLeft = getHintRect(tester).left;

      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText, maintainHintSize: false),
        ),
      );
      expect(getHintRect(tester).left, expectedHintLeft);
    });

    testWidgets('Hint does not change position when maintainHintSize is false - RTL', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText),
          textDirection: TextDirection.rtl,
        ),
      );
      final double expectedHintRight = getHintRect(tester).right;

      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText, maintainHintSize: false),
          textDirection: TextDirection.rtl,
        ),
      );
      expect(getHintRect(tester).right, expectedHintRight);
    });

}

static Widget _topLeftLayout(Widget? currentChild, List<Widget> previousChildren) {
return Stack(
Copy link
Contributor

Choose a reason for hiding this comment

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

What about using an Align widget?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@justinmc

What about using an Align widget?

@justinmc Thank you for your suggestion, but layoutBuilder needs to return multiple children. It seems that this cannot be done if Align is used? The defaultLayoutBuilder implementation uses Stack to center the layout.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah right, I think this is good as-is then.

zeqinjie and others added 3 commits May 19, 2025 10:28
* master: (125 commits)
  Roll Fuchsia Linux SDK from XtPp9bBW49iDJ0wbA... to -eo2JqnJBauuGSzoW... (flutter#169424)
  Roll Skia from 91dc88dc70e5 to 443f5257f382 (1 revision) (flutter#169422)
  Roll Skia from 0834eea9de33 to 91dc88dc70e5 (1 revision) (flutter#169414)
  Roll Dart SDK from 0a6b16a55b9e to 7dab9bffe1f7 (1 revision) (flutter#169406)
  Correct calculation for CupertinoTextSelectionToolbar vertical position (flutter#169308)
  Baseline-align CupertinoTextField placeholder (flutter#166952)
  Roll Dart SDK from 8354914ef97b to 0a6b16a55b9e (3 revisions) (flutter#169403)
  Start removing Observatory support and references (flutter#169216)
  Roll Skia from f42bb59753fe to 0834eea9de33 (3 revisions) (flutter#169393)
  Roll Skia from 956fd8b14e22 to f42bb59753fe (2 revisions) (flutter#169379)
  [Engine] Fast blurring algorithm for RSuperellipse (flutter#169187)
  Add a page describing best CI practices for `flutter`-org repos (flutter#169364)
  Revert "Mark web_tool_tests_1_2 as bringup." (flutter#169361)
  Add changelog section for 3.32.0 and 3.32.1, and add note for ndk checking cherry pick (flutter#169369)
  Roll Dart SDK from 085f110ecf33 to 8354914ef97b (1 revision) (flutter#169349)
  Remove handling of the legacy `.flutter-plugins` file in `PluginHandler.kt`. (flutter#169317)
  Use baseUri of WebAssetServer for reload_scripts.json (flutter#169267)
  Reverts "Use pub workspace (flutter#168662)" (flutter#169357)
  Use pub workspace (flutter#168662)
  Reverts "[Reland2] Implements UISceneDelegate dynamically w/ FlutterLaunchEngine (flutter#169276)" (flutter#169347)
  ...
@dkwingsmt
Copy link
Contributor

@justinmc Can you take a look? The contributor answered your comments. (from triage)

@zeqinjie zeqinjie requested a review from justinmc June 22, 2025 02:28
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 👍 Sorry for the delay on reviewing this. I will look for a secondary reviewer.

Copy link
Contributor

@bleroux bleroux 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 your contribution 🙏
I added a comment related to RTL text direction and also I proposed to simplify the test.

return FadeTransition(opacity: _curvedAnimation!, child: child);
}

static Widget _topLeftLayout(Widget? currentChild, List<Widget> previousChildren) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be _topStartLayout and set the Stack.alignment property to Alignment.topStart (in order to support TextDirection.rtl).

Comment on lines 2293 to 2298
return Stack(
alignment: Alignment.topLeft,
children: <Widget>[...previousChildren, if (currentChild != null) currentChild],
);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return Stack(
alignment: Alignment.topLeft,
children: <Widget>[...previousChildren, if (currentChild != null) currentChild],
);
}
static Widget _topStartLayout(Widget? currentChild, List<Widget> previousChildren) {
return Stack(children: <Widget>[...previousChildren, if (currentChild != null) currentChild]);
}

In order to support RTL (TextDirection.rtl), this should probably be named _topStartLayoutand because this is the default alignment value for Stack the property does not need to be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@bleroux Thank you for your guidance, I have studied. Updated


final Stack stack = tester.widget<Stack>(stackFinder);
expect(stack.alignment, Alignment.topLeft);
});
Copy link
Contributor

@bleroux bleroux Jun 23, 2025

Choose a reason for hiding this comment

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

I proposed to simplify this test by checking if the hint position changes for maintainHintSize: false compared to maintaintHintSize: true.
That way the tests are simpler and does not depend on implementations details (AnimatedSwitcher and its Stack).

    testWidgets('Hint does not change position when maintainHintSize is false - LTR', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        buildInputDecorator(isEmpty: true, decoration: const InputDecoration(hintText: hintText)),
      );
      final double expectedHintLeft = getHintRect(tester).left;

      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText, maintainHintSize: false),
        ),
      );
      expect(getHintRect(tester).left, expectedHintLeft);
    });

    testWidgets('Hint does not change position when maintainHintSize is false - RTL', (
      WidgetTester tester,
    ) async {
      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText),
          textDirection: TextDirection.rtl,
        ),
      );
      final double expectedHintRight = getHintRect(tester).right;

      await tester.pumpWidget(
        buildInputDecorator(
          isEmpty: true,
          decoration: const InputDecoration(hintText: hintText, maintainHintSize: false),
          textDirection: TextDirection.rtl,
        ),
      );
      expect(getHintRect(tester).right, expectedHintRight);
    });

@zeqinjie zeqinjie requested a review from bleroux June 24, 2025 06:57
Copy link
Contributor

@bleroux bleroux left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks 🙏

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Jun 24, 2025
Merged via the queue into flutter:master with commit dd89ae9 Jun 24, 2025
69 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 24, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jun 25, 2025
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jun 26, 2025
Roll Flutter from d733bea58c1a to 2773c0c8e15e (42 revisions)

flutter/flutter@d733bea...2773c0c

2025-06-25 [email protected] Log stack traces from exceptions thrown by devicelab test tasks (flutter/flutter#171165)
2025-06-25 [email protected] Revert "Move `web_long_running_tests_{1,5}_5` to `bringup`." (flutter/flutter#171100)
2025-06-25 [email protected] Add missing M3 tests for InputDecoration.isDense (flutter/flutter#171058)
2025-06-25 [email protected] Add Android specific sub-step to validate the Android sdk path has no spaces (flutter/flutter#170829)
2025-06-24 [email protected] Update foundation library to export internal (flutter/flutter#170563)
2025-06-24 [email protected] Remove stale references to `Release-process.md` and `conductor` (flutter/flutter#171046)
2025-06-24 [email protected] License cpp jun23 (flutter/flutter#171047)
2025-06-24 [email protected] Add android-reviewers to CODEOWNERS (flutter/flutter#170157)
2025-06-24 [email protected] Update tool/README.md regarding locally-built engine (flutter/flutter#171102)
2025-06-24 [email protected] [web] Align the PR triage process with the ecosystem's triage flow (flutter/flutter#171086)
2025-06-24 [email protected] [flutter_tool] Migrate DAP off `ProcessUtils.writelnToStdinUnsafe` (flutter/flutter#171081)
2025-06-24 [email protected] [web] More granular configuration of the test environment (flutter/flutter#168767)
2025-06-24 [email protected] Clean up Devfs_Web into separate files (flutter/flutter#170769)
2025-06-24 [email protected] Add RawMenuAnchor animation callbacks (flutter/flutter#167806)
2025-06-24 [email protected] Support wide gamut colors when applying a DlColor to an SkPaint (flutter/flutter#170613)
2025-06-24 [email protected] Remove temporary workaround for web testing (flutter/flutter#170949)
2025-06-24 [email protected] Roll Packages from 02770da to d9d3191 (6 revisions) (flutter/flutter#171075)
2025-06-24 [email protected] Add LLDB warnings (flutter/flutter#170827)
2025-06-24 [email protected] Update FormField.initialValue documentation (flutter/flutter#171061)
2025-06-24 [email protected] Roll Skia from 132cb2052565 to a462e701b493 (2 revisions) (flutter/flutter#171063)
2025-06-24 [email protected] Roll Skia from f88706e3a863 to 132cb2052565 (4 revisions) (flutter/flutter#171057)
2025-06-24 [email protected] When maintainHintSize is false, hint is centered and aligned, it is different from the original one (flutter/flutter#168654)
2025-06-24 [email protected] Deprecate DropdownButtonFormField "value" parameter in favor of "initialValue" (flutter/flutter#170805)
2025-06-24 [email protected] Roll Skia from af6feb799ea6 to f88706e3a863 (2 revisions) (flutter/flutter#171056)
2025-06-24 [email protected] Roll Dart SDK from aebd78999b1a to d9edd9e7a634 (1 revision) (flutter/flutter#171053)
2025-06-24 [email protected] Roll Skia from ae517eba0170 to af6feb799ea6 (1 revision) (flutter/flutter#171052)
2025-06-24 [email protected] Roll Skia from a7735d517e6a to ae517eba0170 (9 revisions) (flutter/flutter#171049)
2025-06-24 [email protected] Enable interpretation fallback when unable to JIT on iOS. (flutter/flutter#170835)
2025-06-24 [email protected] Flutter test cleanup (flutter/flutter#170891)
2025-06-24 [email protected] Move `packages_autoroller` out of the carcass of `conductor`, delete `conductor` (flutter/flutter#171029)
2025-06-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Don't strip symbols from `libapp.so` on android by default (#162464)" (flutter/flutter#171044)
2025-06-23 [email protected] Roll Dart SDK from a09de0d3556c to aebd78999b1a (2 revisions) (flutter/flutter#171039)
2025-06-23 [email protected] Don't strip symbols from `libapp.so` on android by default (flutter/flutter#162464)
2025-06-23 [email protected] Roll Skia from 0311837abe86 to a7735d517e6a (12 revisions) (flutter/flutter#171037)
2025-06-23 [email protected] Pass font scanner to font mgr that need it (flutter/flutter#170701)
2025-06-23 [email protected] Make service worker tests more lenient. (flutter/flutter#170939)
2025-06-23 [email protected] Remove update CHANGELOG step from stable cherry pick process (flutter/flutter#171017)
2025-06-23 [email protected] Include dev_dependencies in all builds for iOS and macOS (flutter/flutter#171015)
2025-06-23 [email protected] Move `web_long_running_tests_{1,5}_5` to `bringup`. (flutter/flutter#171026)
2025-06-23 [email protected] rename from announce to supportsAnnounce on engine (flutter/flutter#170618)
2025-06-23 [email protected] Roll pub packages (flutter/flutter#171016)
2025-06-23 [email protected] Enhance Text Contrast for WCAG AAA Compliance (flutter/flutter#170758)

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
...
mboetger pushed a commit to mboetger/flutter that referenced this pull request Jul 21, 2025
…ifferent from the original one (flutter#168654)

This PR changes the Hint uses topLeft alignment when maintainHintSize is
false
> code
```dart
buildTextField() {
  return const Center(
    child: TextField(
      decoration: InputDecoration(
        hintText: 'hint',
        maintainHintSize: false,
      ),
    ),
  );
}
```

Before:

<img width="416" alt="b"
src="https://github.com/user-attachments/assets/fe58c2d0-4d37-4bca-aabc-0f7d4785fb2a"
/>

After:
<img width="415" alt="a"
src="https://github.com/user-attachments/assets/096fd83a-9d8f-4cb7-be1d-c3075acbfdc0"
/>



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

---------

Co-authored-by: 郑泽钦 <[email protected]>
@zeqinjie zeqinjie deleted the fix_top_left branch July 25, 2025 13:11
vashworth pushed a commit to vashworth/packages that referenced this pull request Jul 30, 2025
…r#9495)

Roll Flutter from d733bea58c1a to 2773c0c8e15e (42 revisions)

flutter/flutter@d733bea...2773c0c

2025-06-25 [email protected] Log stack traces from exceptions thrown by devicelab test tasks (flutter/flutter#171165)
2025-06-25 [email protected] Revert "Move `web_long_running_tests_{1,5}_5` to `bringup`." (flutter/flutter#171100)
2025-06-25 [email protected] Add missing M3 tests for InputDecoration.isDense (flutter/flutter#171058)
2025-06-25 [email protected] Add Android specific sub-step to validate the Android sdk path has no spaces (flutter/flutter#170829)
2025-06-24 [email protected] Update foundation library to export internal (flutter/flutter#170563)
2025-06-24 [email protected] Remove stale references to `Release-process.md` and `conductor` (flutter/flutter#171046)
2025-06-24 [email protected] License cpp jun23 (flutter/flutter#171047)
2025-06-24 [email protected] Add android-reviewers to CODEOWNERS (flutter/flutter#170157)
2025-06-24 [email protected] Update tool/README.md regarding locally-built engine (flutter/flutter#171102)
2025-06-24 [email protected] [web] Align the PR triage process with the ecosystem's triage flow (flutter/flutter#171086)
2025-06-24 [email protected] [flutter_tool] Migrate DAP off `ProcessUtils.writelnToStdinUnsafe` (flutter/flutter#171081)
2025-06-24 [email protected] [web] More granular configuration of the test environment (flutter/flutter#168767)
2025-06-24 [email protected] Clean up Devfs_Web into separate files (flutter/flutter#170769)
2025-06-24 [email protected] Add RawMenuAnchor animation callbacks (flutter/flutter#167806)
2025-06-24 [email protected] Support wide gamut colors when applying a DlColor to an SkPaint (flutter/flutter#170613)
2025-06-24 [email protected] Remove temporary workaround for web testing (flutter/flutter#170949)
2025-06-24 [email protected] Roll Packages from 02770da to d9d3191 (6 revisions) (flutter/flutter#171075)
2025-06-24 [email protected] Add LLDB warnings (flutter/flutter#170827)
2025-06-24 [email protected] Update FormField.initialValue documentation (flutter/flutter#171061)
2025-06-24 [email protected] Roll Skia from 132cb2052565 to a462e701b493 (2 revisions) (flutter/flutter#171063)
2025-06-24 [email protected] Roll Skia from f88706e3a863 to 132cb2052565 (4 revisions) (flutter/flutter#171057)
2025-06-24 [email protected] When maintainHintSize is false, hint is centered and aligned, it is different from the original one (flutter/flutter#168654)
2025-06-24 [email protected] Deprecate DropdownButtonFormField "value" parameter in favor of "initialValue" (flutter/flutter#170805)
2025-06-24 [email protected] Roll Skia from af6feb799ea6 to f88706e3a863 (2 revisions) (flutter/flutter#171056)
2025-06-24 [email protected] Roll Dart SDK from aebd78999b1a to d9edd9e7a634 (1 revision) (flutter/flutter#171053)
2025-06-24 [email protected] Roll Skia from ae517eba0170 to af6feb799ea6 (1 revision) (flutter/flutter#171052)
2025-06-24 [email protected] Roll Skia from a7735d517e6a to ae517eba0170 (9 revisions) (flutter/flutter#171049)
2025-06-24 [email protected] Enable interpretation fallback when unable to JIT on iOS. (flutter/flutter#170835)
2025-06-24 [email protected] Flutter test cleanup (flutter/flutter#170891)
2025-06-24 [email protected] Move `packages_autoroller` out of the carcass of `conductor`, delete `conductor` (flutter/flutter#171029)
2025-06-23 98614782+auto-submit[bot]@users.noreply.github.com Reverts "Don't strip symbols from `libapp.so` on android by default (#162464)" (flutter/flutter#171044)
2025-06-23 [email protected] Roll Dart SDK from a09de0d3556c to aebd78999b1a (2 revisions) (flutter/flutter#171039)
2025-06-23 [email protected] Don't strip symbols from `libapp.so` on android by default (flutter/flutter#162464)
2025-06-23 [email protected] Roll Skia from 0311837abe86 to a7735d517e6a (12 revisions) (flutter/flutter#171037)
2025-06-23 [email protected] Pass font scanner to font mgr that need it (flutter/flutter#170701)
2025-06-23 [email protected] Make service worker tests more lenient. (flutter/flutter#170939)
2025-06-23 [email protected] Remove update CHANGELOG step from stable cherry pick process (flutter/flutter#171017)
2025-06-23 [email protected] Include dev_dependencies in all builds for iOS and macOS (flutter/flutter#171015)
2025-06-23 [email protected] Move `web_long_running_tests_{1,5}_5` to `bringup`. (flutter/flutter#171026)
2025-06-23 [email protected] rename from announce to supportsAnnounce on engine (flutter/flutter#170618)
2025-06-23 [email protected] Roll pub packages (flutter/flutter#171016)
2025-06-23 [email protected] Enhance Text Contrast for WCAG AAA Compliance (flutter/flutter#170758)

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
...
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 14, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 15, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 16, 2025
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants