Skip to content

Fix reselection issue after the text is cleared#183545

Merged
auto-submit[bot] merged 3 commits intoflutter:masterfrom
QuncCccccc:autocomplete_able_to_reselect
Mar 13, 2026
Merged

Fix reselection issue after the text is cleared#183545
auto-submit[bot] merged 3 commits intoflutter:masterfrom
QuncCccccc:autocomplete_able_to_reselect

Conversation

@QuncCccccc
Copy link
Contributor

Fixes #182927

This PR is to fix a Autocomplete re-selection issue when an option is cleared up and re-selected again. When _select() is called, _selecting is set to true and the _textEditingController is updated which caused _onChangedField() be called but returned early. In this case, we should update _lastFieldText to the newSelection.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • 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.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 11, 2026
@QuncCccccc QuncCccccc force-pushed the autocomplete_able_to_reselect branch from 9cc001a to ebfe5b1 Compare March 11, 2026 22:32
@QuncCccccc QuncCccccc requested a review from justinmc March 11, 2026 23:17
@QuncCccccc QuncCccccc marked this pull request as ready for review March 11, 2026 23:18
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a re-selection issue in the Autocomplete widget. The fix involves updating the _lastFieldText variable within the _select method in packages/flutter/lib/src/widgets/autocomplete.dart. This ensures the widget's internal state correctly tracks the text field's content after a selection, which resolves an issue when clearing the text and re-selecting an option. A new widget test has also been added in packages/flutter/test/widgets/autocomplete_test.dart to verify this specific scenario.

body: Row(
children: <Widget>[
Expanded(
child: Autocomplete<String>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be RawAutocomplete? Autocomplete is the Material version.

final listItem = <String>['test', 'abc', 'dexter'];

await tester.pumpWidget(
MaterialApp(
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice if we could test this without Material widgets.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this! I moved this unit test to test/material/ and created a similar one for RawAutocomplete in test/widgets/

@github-actions github-actions bot added the f: material design flutter/packages/flutter/material repository. label Mar 11, 2026
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

LGTM, the test duplication is a little weird to me but I don't immediately see any cons and it might be useful in case someday Autocomplete no longer depends on RawAutocomplete.

@QuncCccccc
Copy link
Contributor Author

QuncCccccc commented Mar 11, 2026

Yeah.. I wanted to keep the test in the material folder because the original issue uses the material Autocomplete as the sample code. Just wanted to provide a straightforward way to show we fixed the issue but also think it might be better to add a test in widgets because we updated the RawAutocomplete😅

Thanks a lot for helping review!

@QuncCccccc QuncCccccc added the CICD Run CI/CD label Mar 12, 2026
@fluttergithubbot
Copy link
Contributor

An existing Git SHA, c69788dbd4d8a6dd1120066c7a8ef94e201bbd00, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 12, 2026
@Piinks Piinks added CICD Run CI/CD and removed CICD Run CI/CD labels Mar 12, 2026
@fluttergithubbot
Copy link
Contributor

An existing Git SHA, c69788dbd4d8a6dd1120066c7a8ef94e201bbd00, was detected, and no actions were taken.

To re-trigger presubmits after closing or re-opeing a PR, or pushing a HEAD commit (i.e. with --force) that already was pushed before, push a blank commit (git commit --allow-empty -m "Trigger Build") or rebase to continue.

@QuncCccccc QuncCccccc force-pushed the autocomplete_able_to_reselect branch from c69788d to 28f3313 Compare March 12, 2026 22:25
@QuncCccccc QuncCccccc added CICD Run CI/CD and removed CICD Run CI/CD labels Mar 12, 2026
@auto-submit auto-submit bot added this pull request to the merge queue Mar 13, 2026
Merged via the queue into flutter:master with commit 9afbf97 Mar 13, 2026
75 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 13, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 14, 2026
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Mar 14, 2026
flutter/flutter@9e36adb...732e05d

2026-03-13 [email protected] Roll Dart SDK from 330b797abd09 to d5f6d3c17499 (1 revision) (flutter/flutter#183640)
2026-03-13 [email protected] Roll Skia from 9eb5598e1b2c to 029229d8be91 (3 revisions) (flutter/flutter#183638)
2026-03-13 [email protected] Roll Skia from 9be8fdf31ff4 to 9eb5598e1b2c (2 revisions) (flutter/flutter#183630)
2026-03-13 [email protected] Add awaits to flutter/test callsites (flutter/flutter#183487)
2026-03-13 [email protected] Add await to more flutter/flutter callsites (flutter/flutter#183413)
2026-03-13 [email protected] Roll Dart SDK from d1d84ab7ef0d to 330b797abd09 (2 revisions) (flutter/flutter#183624)
2026-03-13 [email protected] refactor: remove material import from sliver_resizing_header_test and sliver_prototype_item_extent_test (flutter/flutter#183562)
2026-03-13 [email protected] Fix reselection issue after the text is cleared (flutter/flutter#183545)
2026-03-13 [email protected] Roll Skia from 255bd243276b to 9be8fdf31ff4 (5 revisions) (flutter/flutter#183616)
2026-03-12 [email protected] ci: Remove `bringup` from orchestrator for windows_arm_host_engine on Linux (flutter/flutter#183574)
2026-03-12 [email protected] Use operator<=> instead of std::less for UniqueID. (flutter/flutter#183600)
2026-03-12 [email protected] Specified the repo the cp label will be removed from (flutter/flutter#183611)
2026-03-12 [email protected] [web] Fix Web SDK build on macOS (flutter/flutter#183549)
2026-03-12 [email protected] Roll Skia from 38761e1803d0 to 255bd243276b (3 revisions) (flutter/flutter#183603)
2026-03-12 [email protected] Roll Dart SDK from 2e1e7a09fce6 to d1d84ab7ef0d (1 revision) (flutter/flutter#183604)
2026-03-12 [email protected] Fix macOS relative plugin Xcode file path (flutter/flutter#183593)
2026-03-12 [email protected] Made cp labels get rejected on issues. (flutter/flutter#183595)
2026-03-12 [email protected] Roll Packages from ecace66 to 02f231f (4 revisions) (flutter/flutter#183594)
2026-03-12 [email protected] Roll Dart SDK from 59be21f25f2d to 2e1e7a09fce6 (1 revision) (flutter/flutter#183577)
2026-03-12 [email protected] Roll Skia from 46f41493ebf4 to 38761e1803d0 (6 revisions) (flutter/flutter#183590)

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] 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

CICD Run CI/CD 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.

[AutoComplete] Once an option has been selected (including using Enter), it can no longer be selected again (Regression)

4 participants