Skip to content

Fix lower DragTarget not being recognized in overlapping targets#188979

Open
Aurelius51 wants to merge 1 commit into
flutter:masterfrom
Aurelius51:fix-187543-dragtarget-overlap
Open

Fix lower DragTarget not being recognized in overlapping targets#188979
Aurelius51 wants to merge 1 commit into
flutter:masterfrom
Aurelius51:fix-187543-dragtarget-overlap

Conversation

@Aurelius51

Copy link
Copy Markdown

Fixes #187543
Fixes #143156

_DragAvatar.updateDrag bails early when the hit-tested targets share a
prefix with _enteredTargets. That optimization (the pass-through path,
refined in #60174) is only correct once a target has accepted the drag
(_activeTarget != null), because deeper targets below the active one are
intentionally ignored. When nothing has accepted yet, _enteredTargets
contains every hit target, so a newly-appearing lower target makes the hit
list longer while still prefix-matching, and the code bailed without
entering it. Dragging over an upper rejecting target and then into an
overlap therefore left the lower target unrecognized.

The fix only takes the early-bail when _activeTarget != null or the target
set is exactly unchanged, so the fast-path is preserved once a target has
accepted, while a newly-appearing lower target is re-evaluated when nothing
has accepted.

Tests

Added a regression test (over an upper rejecting target, then into the
overlap, the lower target now accepts; verified it fails without the fix and
passes with it) and a guard test (when the upper target accepts, the drag
does not fall through to a lower overlapping target). The full
draggable_test.dart suite passes.

Design note

When nothing has accepted yet and a new lower target appears, the existing
leave/re-enter path re-evaluates the targets, which fires onLeave once on
the still-hovered upper target before re-entering it. This matches existing
behavior whenever the entered-target set changes and is intentionally
minimal; a plain == check would instead defeat the accepted-target
fast-path.

@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 5, 2026

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

Copy link
Copy Markdown
Contributor

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 updates the early-bail logic in _DragAvatar inside drag_target.dart by requiring an exact-length match of hit targets when no target has accepted the drag yet. This allows lower overlapping targets to be recognized when an upper target rejects the drag. Additionally, two test cases are added to draggable_test.dart to verify this new behavior and ensure that accepting upper targets are not bypassed. There are no review comments, so no further feedback is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_DragAvatar.updateDrag, listsMatch calculation may prevent new "lower" DragTarget from being recognized Issue with stacked DragTargets

1 participant