fix: prefer topmost route when resolving tap/enter_text by text/key#53
Open
ReniDelonzek wants to merge 1 commit into
Open
Conversation
When a screen is pushed over another that stays mounted, _findElementByText and _findElementByKey returned the first match in a pre-order tree walk — which is the background route (mounted first). So tap(text:)/tap(key:) could hit an element hidden behind the current screen (e.g. a tab label on the visible screen that also exists as a list subtitle on the screen behind it). Collect all matches and return the last one. In Overlay/Navigator order the foreground route is mounted last and therefore visited last, so the last match targets the screen the user actually sees. A center hit-test could refine this further and is noted as a follow-up. Applied to both the canonical lib/ source and the bundled npm copy. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
When a screen is pushed over another that stays mounted (a very common Navigator/Overlay pattern),
_findElementByTextand_findElementByKeyinflutter_skill.dartwalk the entire element tree fromrootElementand return the first match. In pre-order traversal the background route (mounted first) is visited before the foreground one, sotap(text:)/tap(key:)can hit an element that is invisible, behind the current screen.Concrete case: a foreground screen has a tab labeled
"X"while the background screen (still mounted underneath) also renders"X"as a list subtitle.tap(text: "X")lands on the background occurrence instead of the visible tab.This is tracked in #52 (Problem 2).
Fix
Collect all matches and return the last one. In Overlay/Navigator order the foreground route is mounted last and therefore visited last, so the last match targets the screen the user actually sees. Minimal, dependency-free, and strictly better than first-match for stacked routes (single-match behavior is unchanged).
Applied to both the canonical
lib/flutter_skill.dartand the bundledpackaging/npm/dart/lib/flutter_skill.dart.Follow-ups (not in this PR, see #52)
tapbyrefand byx/y("Must provide key or text for tap") even though the same-tag source already implements them — looks like the shipped binary lags the source and needs a rebuild/republish.enter_text/tapbySemantics.identifier/label(or nearest descendantEditableText) so wrapped/masked fields without aValueKeyare addressable.Notes
dart formaton the touched files: the formatter reflows ~900 lines (repo style differs from defaultdart format), which would bury the change. The edit follows the surrounding style. Happy to adjust if the project has a specific format step.