Skip to content

Add support for language hints in TextFields (Android only) #165554

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

Merged
merged 3 commits into from
Apr 17, 2025

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Mar 20, 2025

Description

This PR adds support for language hints in TextFields.
This is supported only on Android for the moment and the property name, aka TextField.hintLocales, is based on Android's EditorInfo.hintLocales property, see https://developer.android.com/reference/android/view/inputmethod/EditorInfo#hintLocales.

Related Issue

Fixes Support for language hints in TextFields

Tests

Adds 4 tests.
Updates several tests.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems platform-android Android applications specifically framework flutter/packages/flutter repository. See also f: labels. engine flutter/engine repository. See also e: labels. f: material design flutter/packages/flutter/material repository. labels Mar 20, 2025
@bleroux bleroux force-pushed the add_ime_hint_locales branch 5 times, most recently from d6214e6 to 08ef92e Compare March 24, 2025 09:32
@bleroux bleroux requested a review from justinmc March 24, 2025 13:06
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 taking this on @bleroux! It's always extra work to add engine+framework features like this.

Can you take a quick look at the iOS docs (if you haven't already) to see if they have a similar feature? I just want to make sure that what we're adding is more or less compatible if so. If you can reassure me there then LGTM.

@reidbaker Would you be able to back me up by reviewing the Android code in this PR?

@bleroux
Copy link
Contributor Author

bleroux commented Mar 25, 2025

Can you take a quick look at the iOS docs (if you haven't already) to see if they have a similar feature?

I found https://developer.apple.com/documentation/uikit/uitextinputmode/primarylanguage which accepts one language tag instead of a list of locales. It looks like we would be able to provide this feature for iOS and macOS 🎉. The comment will reflect that only the first locale is used on iOS.

@justinmc Do you think we should keep the name 'hintLocales' or used something agnostic such as 'preferredLocales'?

@bleroux bleroux force-pushed the add_ime_hint_locales branch from 08ef92e to da3401d Compare March 25, 2025 08:17
@jesswrd jesswrd requested a review from reidbaker March 25, 2025 18:44
@bleroux bleroux force-pushed the add_ime_hint_locales branch from da3401d to 3f9cbf6 Compare March 27, 2025 13:16
@justinmc
Copy link
Contributor

@bleroux Let's say we keep the name hintLocales but add iOS support later. Are you thinking that iOS will take the first item in the list since it only supports one? Are the strings compatible like that?

Overall I don't have a strong opinion about the name at the EditableText/TextField level. However at the TextInputConfiguration level I wonder if we can support both separately via different values in TextInputConfiguration? In order to give fine grained control to users that might want that.

Maybe it's such a simple feature that fine grained control doesn't really matter in this case, but that's the approach I generally try to take for these kinds of cross platform APIs.

@bleroux
Copy link
Contributor Author

bleroux commented Mar 27, 2025

Let's say we keep the name hintLocales but add iOS support later.

Perfectly fine to me. 👍

Are you thinking that iOS will take the first item in the list since it only supports one? Are the strings compatible like that?

Yes, It was my thinking. And yes the strings are compatible because the string expected by iOS is the result of Locale.toLanguageTag().

However at the TextInputConfiguration level I wonder if we can support both separately via different values in TextInputConfiguration? In order to give fine grained control to users that might want that.

Great point! I will have to think about it and share my findings.

Maybe it's such a simple feature that fine grained control doesn't really matter in this case, but that's the approach I generally try to take for these kinds of cross platform APIs.

Very interesting, thank you for sharing this.

@reidbaker reidbaker requested review from a team and removed request for reidbaker April 8, 2025 18:56
Copy link
Contributor

@camsim99 camsim99 left a comment

Choose a reason for hiding this comment

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

Android parts look solid to me!

@bleroux bleroux requested a review from justinmc April 14, 2025 18:46
@bleroux
Copy link
Contributor Author

bleroux commented Apr 14, 2025

Thanks @camsim99! 🙏

@justinmc Based on #165554 (comment) do you think we can proceed with this PR? Once merged I will work on the iOS support.

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 with respect to the future iOS support 👍 . So this PR supports only Android and uses the native Android name hintLocales. Native iOS calls it primaryLanguage, and that name is still available to us in case we find some reason to use both. Otherwise we can keep everything under hintLocales.

@bleroux bleroux force-pushed the add_ime_hint_locales branch from 3f9cbf6 to 3b50a7b Compare April 17, 2025 08:34
@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Apr 17, 2025
Merged via the queue into flutter:master with commit fbed8a7 Apr 17, 2025
176 of 177 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2025
@bleroux bleroux deleted the add_ime_hint_locales branch April 17, 2025 12:35
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Apr 17, 2025
flutter/flutter@aef4718...ecabb1a

2025-04-17 15619084+vashworth@users.noreply.github.com Hide error on mDNS registration failure and print warning in flutter attach (flutter/flutter#166782)
2025-04-17 bruno.leroux@gmail.com Add support for language hints in TextFields (Android only) (flutter/flutter#165554)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from d8f13372549d to cc2b57434651 (1 revision) (flutter/flutter#167331)
2025-04-17 bruno.leroux@gmail.com Add DropdownMenu.restorationId (flutter/flutter#166684)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 3d6165b70199 to d8f13372549d (14 revisions) (flutter/flutter#167325)
2025-04-17 stanleycocoa@gmail.com fix(CircularProgressIndicator.adaptive): strokeWidth default value (flutter/flutter#165370)
2025-04-17 ahmedelsaayid@gmail.com Remove unnecessary builder (flutter/flutter#166623)
2025-04-17 34871572+gmackall@users.noreply.github.com Add a `gradle_errors.dart`entry for missing NDK source.properties file (flutter/flutter#167320)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 6627deb65939 to 3d6165b70199 (1 revision) (flutter/flutter#167255)
2025-04-17 engine-flutter-autoroll@skia.org Manual roll Dart SDK from 87965ab4864e to 992221a362ec (35 revisions) (flutter/flutter#167243)
2025-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 7bWzHwIPBTyU6R9nO... to m8Aln7fTF_8zy1V9N... (flutter/flutter#167312)
2025-04-16 15619084+vashworth@users.noreply.github.com Don't throw on error for mDNS when searching for Dart VML url on core devices (flutter/flutter#167135)
2025-04-16 34465683+rkishan516@users.noreply.github.com Fix: Localization for non zero time in 24 hours format (flutter/flutter#164885)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Updated docstrings for TextureContents (flutter/flutter#167221)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Broke cyclical dependency with dlpath and typographer. (flutter/flutter#167293)
2025-04-16 34871572+gmackall@users.noreply.github.com Set an additional CMake arg in `forceNdkDownload` to make the task name align with the `BuildType` (flutter/flutter#167240)
2025-04-16 huy@nevercode.io Fix Carousel crashes when using PageStorageKey (flutter/flutter#166817)
2025-04-16 jason-simmons@users.noreply.github.com Revert "Removed superfluous copy in license checker (#167146)" (flutter/flutter#167246)
2025-04-16 dacoharkes@google.com [native assets] Roll dependencies (flutter/flutter#167287)
2025-04-16 fluttergithubbot@gmail.com Marks Linux_pixel_7pro static_path_stroke_tessellation_perf__timeline_summary to be unflaky (flutter/flutter#167259)
2025-04-16 34465683+rkishan516@users.noreply.github.com Feat: Add carousel view theme (flutter/flutter#164769)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios dynamic_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167261)
2025-04-16 jason-simmons@users.noreply.github.com When using --local-web-sdk, use a locally built Dart SDK if one is available (flutter/flutter#166732)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Added emulator version to doctor (flutter/flutter#167236)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios static_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167260)

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 stuartmorgan@google.com,tarrinneal@google.com 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
ash2moon pushed a commit to ash2moon/flutter that referenced this pull request Apr 21, 2025
…165554)

## Description

This PR adds support for language hints in TextFields.
This is supported only on Android for the moment and the property name,
aka `TextField.hintLocales`, is based on Android's
`EditorInfo.hintLocales` property, see
https://developer.android.com/reference/android/view/inputmethod/EditorInfo#hintLocales.

## Related Issue

Fixes [Support for language hints in
TextFields](flutter#163698)

## Tests

Adds 4 tests.
Updates several tests.
CodixNinja pushed a commit to CodixNinja/packages that referenced this pull request May 15, 2025
flutter/flutter@aef4718...ecabb1a

2025-04-17 15619084+vashworth@users.noreply.github.com Hide error on mDNS registration failure and print warning in flutter attach (flutter/flutter#166782)
2025-04-17 bruno.leroux@gmail.com Add support for language hints in TextFields (Android only) (flutter/flutter#165554)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from d8f13372549d to cc2b57434651 (1 revision) (flutter/flutter#167331)
2025-04-17 bruno.leroux@gmail.com Add DropdownMenu.restorationId (flutter/flutter#166684)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 3d6165b70199 to d8f13372549d (14 revisions) (flutter/flutter#167325)
2025-04-17 stanleycocoa@gmail.com fix(CircularProgressIndicator.adaptive): strokeWidth default value (flutter/flutter#165370)
2025-04-17 ahmedelsaayid@gmail.com Remove unnecessary builder (flutter/flutter#166623)
2025-04-17 34871572+gmackall@users.noreply.github.com Add a `gradle_errors.dart`entry for missing NDK source.properties file (flutter/flutter#167320)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 6627deb65939 to 3d6165b70199 (1 revision) (flutter/flutter#167255)
2025-04-17 engine-flutter-autoroll@skia.org Manual roll Dart SDK from 87965ab4864e to 992221a362ec (35 revisions) (flutter/flutter#167243)
2025-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 7bWzHwIPBTyU6R9nO... to m8Aln7fTF_8zy1V9N... (flutter/flutter#167312)
2025-04-16 15619084+vashworth@users.noreply.github.com Don't throw on error for mDNS when searching for Dart VML url on core devices (flutter/flutter#167135)
2025-04-16 34465683+rkishan516@users.noreply.github.com Fix: Localization for non zero time in 24 hours format (flutter/flutter#164885)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Updated docstrings for TextureContents (flutter/flutter#167221)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Broke cyclical dependency with dlpath and typographer. (flutter/flutter#167293)
2025-04-16 34871572+gmackall@users.noreply.github.com Set an additional CMake arg in `forceNdkDownload` to make the task name align with the `BuildType` (flutter/flutter#167240)
2025-04-16 huy@nevercode.io Fix Carousel crashes when using PageStorageKey (flutter/flutter#166817)
2025-04-16 jason-simmons@users.noreply.github.com Revert "Removed superfluous copy in license checker (#167146)" (flutter/flutter#167246)
2025-04-16 dacoharkes@google.com [native assets] Roll dependencies (flutter/flutter#167287)
2025-04-16 fluttergithubbot@gmail.com Marks Linux_pixel_7pro static_path_stroke_tessellation_perf__timeline_summary to be unflaky (flutter/flutter#167259)
2025-04-16 34465683+rkishan516@users.noreply.github.com Feat: Add carousel view theme (flutter/flutter#164769)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios dynamic_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167261)
2025-04-16 jason-simmons@users.noreply.github.com When using --local-web-sdk, use a locally built Dart SDK if one is available (flutter/flutter#166732)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Added emulator version to doctor (flutter/flutter#167236)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios static_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167260)

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 stuartmorgan@google.com,tarrinneal@google.com 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
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
…r#9104)

flutter/flutter@aef4718...ecabb1a

2025-04-17 15619084+vashworth@users.noreply.github.com Hide error on mDNS registration failure and print warning in flutter attach (flutter/flutter#166782)
2025-04-17 bruno.leroux@gmail.com Add support for language hints in TextFields (Android only) (flutter/flutter#165554)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from d8f13372549d to cc2b57434651 (1 revision) (flutter/flutter#167331)
2025-04-17 bruno.leroux@gmail.com Add DropdownMenu.restorationId (flutter/flutter#166684)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 3d6165b70199 to d8f13372549d (14 revisions) (flutter/flutter#167325)
2025-04-17 stanleycocoa@gmail.com fix(CircularProgressIndicator.adaptive): strokeWidth default value (flutter/flutter#165370)
2025-04-17 ahmedelsaayid@gmail.com Remove unnecessary builder (flutter/flutter#166623)
2025-04-17 34871572+gmackall@users.noreply.github.com Add a `gradle_errors.dart`entry for missing NDK source.properties file (flutter/flutter#167320)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 6627deb65939 to 3d6165b70199 (1 revision) (flutter/flutter#167255)
2025-04-17 engine-flutter-autoroll@skia.org Manual roll Dart SDK from 87965ab4864e to 992221a362ec (35 revisions) (flutter/flutter#167243)
2025-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 7bWzHwIPBTyU6R9nO... to m8Aln7fTF_8zy1V9N... (flutter/flutter#167312)
2025-04-16 15619084+vashworth@users.noreply.github.com Don't throw on error for mDNS when searching for Dart VML url on core devices (flutter/flutter#167135)
2025-04-16 34465683+rkishan516@users.noreply.github.com Fix: Localization for non zero time in 24 hours format (flutter/flutter#164885)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Updated docstrings for TextureContents (flutter/flutter#167221)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Broke cyclical dependency with dlpath and typographer. (flutter/flutter#167293)
2025-04-16 34871572+gmackall@users.noreply.github.com Set an additional CMake arg in `forceNdkDownload` to make the task name align with the `BuildType` (flutter/flutter#167240)
2025-04-16 huy@nevercode.io Fix Carousel crashes when using PageStorageKey (flutter/flutter#166817)
2025-04-16 jason-simmons@users.noreply.github.com Revert "Removed superfluous copy in license checker (#167146)" (flutter/flutter#167246)
2025-04-16 dacoharkes@google.com [native assets] Roll dependencies (flutter/flutter#167287)
2025-04-16 fluttergithubbot@gmail.com Marks Linux_pixel_7pro static_path_stroke_tessellation_perf__timeline_summary to be unflaky (flutter/flutter#167259)
2025-04-16 34465683+rkishan516@users.noreply.github.com Feat: Add carousel view theme (flutter/flutter#164769)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios dynamic_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167261)
2025-04-16 jason-simmons@users.noreply.github.com When using --local-web-sdk, use a locally built Dart SDK if one is available (flutter/flutter#166732)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Added emulator version to doctor (flutter/flutter#167236)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios static_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167260)

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 stuartmorgan@google.com,tarrinneal@google.com 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
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
…r#9104)

flutter/flutter@aef4718...ecabb1a

2025-04-17 15619084+vashworth@users.noreply.github.com Hide error on mDNS registration failure and print warning in flutter attach (flutter/flutter#166782)
2025-04-17 bruno.leroux@gmail.com Add support for language hints in TextFields (Android only) (flutter/flutter#165554)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from d8f13372549d to cc2b57434651 (1 revision) (flutter/flutter#167331)
2025-04-17 bruno.leroux@gmail.com Add DropdownMenu.restorationId (flutter/flutter#166684)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 3d6165b70199 to d8f13372549d (14 revisions) (flutter/flutter#167325)
2025-04-17 stanleycocoa@gmail.com fix(CircularProgressIndicator.adaptive): strokeWidth default value (flutter/flutter#165370)
2025-04-17 ahmedelsaayid@gmail.com Remove unnecessary builder (flutter/flutter#166623)
2025-04-17 34871572+gmackall@users.noreply.github.com Add a `gradle_errors.dart`entry for missing NDK source.properties file (flutter/flutter#167320)
2025-04-17 engine-flutter-autoroll@skia.org Roll Skia from 6627deb65939 to 3d6165b70199 (1 revision) (flutter/flutter#167255)
2025-04-17 engine-flutter-autoroll@skia.org Manual roll Dart SDK from 87965ab4864e to 992221a362ec (35 revisions) (flutter/flutter#167243)
2025-04-16 engine-flutter-autoroll@skia.org Roll Fuchsia Linux SDK from 7bWzHwIPBTyU6R9nO... to m8Aln7fTF_8zy1V9N... (flutter/flutter#167312)
2025-04-16 15619084+vashworth@users.noreply.github.com Don't throw on error for mDNS when searching for Dart VML url on core devices (flutter/flutter#167135)
2025-04-16 34465683+rkishan516@users.noreply.github.com Fix: Localization for non zero time in 24 hours format (flutter/flutter#164885)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Updated docstrings for TextureContents (flutter/flutter#167221)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Broke cyclical dependency with dlpath and typographer. (flutter/flutter#167293)
2025-04-16 34871572+gmackall@users.noreply.github.com Set an additional CMake arg in `forceNdkDownload` to make the task name align with the `BuildType` (flutter/flutter#167240)
2025-04-16 huy@nevercode.io Fix Carousel crashes when using PageStorageKey (flutter/flutter#166817)
2025-04-16 jason-simmons@users.noreply.github.com Revert "Removed superfluous copy in license checker (#167146)" (flutter/flutter#167246)
2025-04-16 dacoharkes@google.com [native assets] Roll dependencies (flutter/flutter#167287)
2025-04-16 fluttergithubbot@gmail.com Marks Linux_pixel_7pro static_path_stroke_tessellation_perf__timeline_summary to be unflaky (flutter/flutter#167259)
2025-04-16 34465683+rkishan516@users.noreply.github.com Feat: Add carousel view theme (flutter/flutter#164769)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios dynamic_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167261)
2025-04-16 jason-simmons@users.noreply.github.com When using --local-web-sdk, use a locally built Dart SDK if one is available (flutter/flutter#166732)
2025-04-16 30870216+gaaclarke@users.noreply.github.com Added emulator version to doctor (flutter/flutter#167236)
2025-04-16 fluttergithubbot@gmail.com Marks Mac_ios static_path_stroke_tessellation_perf_ios__timeline_summary to be unflaky (flutter/flutter#167260)

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 stuartmorgan@google.com,tarrinneal@google.com 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems engine flutter/engine repository. See also e: labels. f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. platform-android Android applications specifically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for language hints in TextFields
3 participants