Skip to content

set onChangedField function to only update options with new results#150776

Merged
auto-submit[bot] merged 41 commits intoflutter:masterfrom
mohsinraza-fdev:refactor-autocomplete-onchanged
Sep 3, 2024
Merged

set onChangedField function to only update options with new results#150776
auto-submit[bot] merged 41 commits intoflutter:masterfrom
mohsinraza-fdev:refactor-autocomplete-onchanged

Conversation

@mohsinraza-fdev
Copy link
Contributor

@mohsinraza-fdev mohsinraza-fdev commented Jun 25, 2024

Added function and result identifiers into the RawAutocomplete onChangedField method, now the options value will not be updated if the data is from an optionsBuilder call older than the last call which updated the options

List which issues are fixed by this PR. You must list at least one issue. An issue is not required if the PR fixes something trivial like a typo.
Issue #150774 is fixed by this PR

If you had to change anything in the flutter/tests repo, include a link to the migration guide as per the breaking change policy.

Pre-launch Checklist

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

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact "@test-exemption-reviewer" in the #hackers channel in Chat (don't just cc them here, they won't see it! Use Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

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

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Jun 25, 2024
@goderbauer goderbauer requested a review from justinmc June 25, 2024 22:03
@goderbauer
Copy link
Member

@mohsinraza-fdev Could you please add a test as indicated by the bot message above to make sure we never regress this? Thank you.

@mohsinraza-fdev
Copy link
Contributor Author

@mohsinraza-fdev Could you please add a test as indicated by the bot message above to make sure we never regress this? Thank you.

on it

@mohsinraza-fdev
Copy link
Contributor Author

@mohsinraza-fdev Could you please add a test as indicated by the bot message above to make sure we never regress this? Thank you.

Test added.

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.

There may be a more complete solution in progress by @victorsanni (#147900 and/or #148995). This PR should probably be on hold until we figure out those bigger changes.

Sorry for the confusion @mohsinraza-fdev. I'll assign @victorsanni to #150774 now. I appreciate you submitting your issue and this PR. We'll see if we can move forward with this or if we have to close it.

@mohsinraza-fdev
Copy link
Contributor Author

There may be a more complete solution in progress by @victorsanni (#147900 and/or #148995). This PR should probably be on hold until we figure out those bigger changes.

Sorry for the confusion @mohsinraza-fdev. I'll assign @victorsanni to #150774 now. I appreciate you submitting your issue and this PR. We'll see if we can move forward with this or if we have to close it.

Sure

@justinmc
Copy link
Contributor

I talked to @victorsanni offline and his PR should cover this, but we'll revisit it after his PR is merged and double check. If not then we can move forward with this PR. Sorry again for the duplicate work here.

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.

Talking with @victorsanni, I think we want to merge this PR first and then make the bigger changes in his PR. So let's move forward with this if you're still available! I've left a bunch of small nit comments, except for one where I had an idea to simplify the two int variables. Otherwise I think this PR is ready.

@chunhtai
Copy link
Contributor

Hi @mohsinraza-fdev are you still working on this pr?

@mohsinraza-fdev
Copy link
Contributor Author

Hi @mohsinraza-fdev are you still working on this pr?

Yep, waiting for a reply from @justinmc

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.

Sorry for missing this notification. Feel free to ping me on Discord if that happens again! I do want to get this PR merged.

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 I went a little overboard trying to get rid of the shouldUpdateOptions boolean. Let's keep the behavior the same and merge this as-is.

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 3, 2024
@auto-submit auto-submit bot merged commit 7695582 into flutter:master Sep 3, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 4, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 5, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
chrisbobbe added a commit to chrisbobbe/flutter that referenced this pull request Mar 15, 2026
…ust text

Previously, _onChangedField would call optionsBuilder on every
TextEditingValue change but silently discard the result unless
.text had changed. This meant an optionsBuilder that depended on
.selection or .composing would never see its results applied.

That guard was introduced in 919d205 ("Dismiss Autocomplete with
ESC", flutter#97790) for a narrow purpose: after the user pressed ESC to
hide the options overlay, a selection-only change (e.g. moving the
cursor) should not re-show it. Commit 7695582 (flutter#150776) then
repurposed the same _lastFieldText check to also gate all option
updates, as part of adding race-condition protection for async
optionsBuilder.

This change separates the two concerns:
- Race-condition protection (_onChangedCallId) now applies to every
  call, not just text changes.
- ESC-dismiss behavior is handled by a dedicated _userHidOptions
  flag, which is set when the user presses ESC and cleared when the
  text changes, the field is re-focused, or the user navigates
  options with arrow keys.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App framework flutter/packages/flutter repository. See also f: labels. team-text-input Owned by Text Input team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants