Skip to content

Fix hit test always returning false - #14

Open
ndelanou wants to merge 1 commit into
letsar:masterfrom
ndelanou:fix/hit-test
Open

Fix hit test always returning false#14
ndelanou wants to merge 1 commit into
letsar:masterfrom
ndelanou:fix/hit-test

Conversation

@ndelanou

@ndelanou ndelanou commented Aug 6, 2026

Copy link
Copy Markdown

What

RenderOverflowView.hitTestChildren now visits the onstage children in reverse paint order. It returns true at the first child which is hit.

Why

Fixes #10.

hitTestChildren visited the onstage children, but it always returned false. RenderOverflowView never reported a hit. Descendant gesture detectors still worked, because their entries stay in the hit test result path. But an ancestor which defers the hit test to its child never received the pointer event. A GestureDetector around an OverflowView uses HitTestBehavior.deferToChild by default. Its onTap callback never ran.

The old code had a second defect. It visited the children in paint order, and it did not stop at the first hit. The spacing parameter can be negative to make the children overlap. In that case the bottom child won the gesture arena instead of the top child.

The new code follows RenderBoxContainerDefaultsMixin.defaultHitTestChildren, restricted to the onstage children.

A shorter fix is to return true at the end of the method. That fix makes the whole box opaque. A tap on empty space inside the OverflowView then reports a hit. The gap from spacing and the area below the children are two such places. One of the new tests covers this case.

_hasOverflow needs no extra clip for the hit test. RenderBox.hitTest already checks size.contains(position), and the clip rect is Offset.zero & size.

Test plan

5 new tests in a hit test group:

  • A tap on a child reaches an enclosing GestureDetector, for OverflowView and for OverflowView.flexible.
  • A tap on the overflow indicator reaches it.
  • A tap on an area without any onstage child does not reach an enclosing GestureDetector.
  • A tap on overlapping children reaches the topmost child.
  • A tap on an offstage child does not reach it.

Two of these tests fail on master:

Expected: <1>
  Actual: <0>
Expected: ['B']
  Actual: ['A']

All 13 tests pass with the fix. flutter analyze reports no issues. I ran the suite with Flutter 3.44.8.

Notes

I set the version to 0.5.1 and added a CHANGELOG entry. Change the number if you prefer another one.

dart format with Dart 3.12 wants to reformat lib/src/widgets/overflow_view.dart and test/overflow_view_test.dart. This is already true on master, so I left the formatting alone to keep the diff small. lib/src/rendering/overflow_view.dart needs no format change.

🤖 Generated with Claude Code

hitTestChildren visits the onstage children, but it always returns
false. The RenderOverflowView never reports a hit. An ancestor which
defers the hit test to its child, like a GestureDetector, never
receives the pointer event.

The children are also visited in paint order, and the visit does not
stop at the first hit. With a negative spacing, the children overlap
and the bottom child wins instead of the top one.

Visit the onstage children in reverse paint order. Return true at the
first child which is hit.

Fixes letsar#10

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hit test always returns false

1 participant