fix(binding): resolve elements by semantics identifier and non-String keys - #62
Open
charliewwdev wants to merge 2 commits into
Open
fix(binding): resolve elements by semantics identifier and non-String keys#62charliewwdev wants to merge 2 commits into
charliewwdev wants to merge 2 commits into
Conversation
… keys Lookup by key only matched ValueKey<String>, which left common widgets unreachable (issue #52, problem 3). Design-system fields wrap their inner editable in a private GlobalKey and expose nothing but Semantics(identifier: ...), so an agent had no handle on them at all — only the "focus the field first, then send an empty key" trick worked. Keys built from ints or enums never matched either. Collect candidates in tiers — widget key, then semantics identifier, then semantics label — and return the first non-empty tier. A real key has to win over a semantics annotation because a label is human-readable text that can collide with an unrelated widget's key. Within a tier the existing topmost-route preference still applies. Widening to `ValueKey` of any type is a superset of the old behaviour: the value is compared by its string form, so ValueKey<String> resolves exactly as before. enter_text needs no change — it already descends from the matched element to the nearest EditableText, which is what makes a matched Semantics wrapper usable. Bumps the declared Flutter floor to 3.19, the first release with SemanticsProperties.identifier. The previous ">=3.0.0" was already inaccurate; WidgetsBinding.rootElement needs 3.9.
Correcting the previous commit: 3.19 covers SemanticsProperties.identifier but not Color.withValues at lib/flutter_skill.dart:4552, which landed in 3.27. Verified by grepping the flutter/flutter tags — absent in 3.24.0, present in 3.27.0. This is also why `dart analyze` has been failing on main: CI pins FLUTTER_VERSION to 3.24.0, below what the source needs.
Member
Author
|
Correction to the version claim in the description above: the floor is 3.27.0, not 3.19.0. 3.19 covers This also explains a pre-existing failure worth flagging separately: The second error is fixed by #61. The first needs |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes problem 3 of #52.
Summary
_findElementByKeymatchedValueKey<String>and nothing else, so two common shapes were unaddressable:GlobalKeyand expose onlySemantics(identifier: ...). An agent had no handle on them — the report notes that only the "focus the field, then send an empty key" fallback worked.ValueKey<int>, enum-valued keys, etc. never matched at all.Approach
Candidates are collected in tiers and the first non-empty tier wins:
ValueKeyof any type, compared by string form)Semantics.identifierSemantics.labelOrdering matters: a label is human-readable text that can easily collide with an unrelated widget's key, so a real key must beat a semantics annotation. Within a tier, the topmost-route preference added in #53 still applies.
Widening to
ValueKeyof any type is a superset of the old behaviour —ValueKey<String>resolves exactly as before.enter_textneeded no change:_findEditableTextalready descends from the matched element to the nearestEditableText, which is precisely what makes a matchedSemanticswrapper usable. The new test pins that descent so it cannot regress.Flutter version floor
Bumped
environment.flutterto>=3.19.0— verified viagit tag --containson flutter/flutter#138331 that 3.19.0 is the first release containingSemanticsProperties.identifier. The previous>=3.0.0was already inaccurate:WidgetsBinding.rootElementneeds 3.9.Test plan
New
test/element_lookup_test.dart(7 widget tests):ValueKey<String>still resolves (no regression)ValueKey<int>(42)resolves via'42'Semantics(identifier: 'email_field')wrapping aTextFieldresolves, and anEditableTextis reachable below the matchSemantics(label:)resolvesflutter analyze lib/flutter_skill.dart test/element_lookup_test.dart— no issuesfindElementByKeyForTestingis added as a@visibleForTestingwrapper so the tie-breaking rules can be pinned without exposing the finder publicly.🤖 Generated with Claude Code