hitTest method

  1. @override
bool hitTest(
  1. HitTestResult result, {
  2. required double localX,
  3. required double localY,
})
override

Performs hit-testing at (localX, localY) in this object's coordinate space. Adds matching entries to result, deepest first.

Returns true if this object or a descendant was hit.

Implementation

@override
bool hitTest(
  HitTestResult result, {
  required double localX,
  required double localY,
}) {
  if (localX < 0 ||
      localY < 0 ||
      localX >= size.width ||
      localY >= size.height) {
    return false;
  }

  // Adjust Y by scroll offset when testing children.
  for (var i = children.length - 1; i >= 0; i--) {
    final child = children[i];
    final childX = localX - child.offset.dx;
    final childY = localY + _controller.offset - child.offset.dy;
    if (child.hitTest(result, localX: childX, localY: childY)) {
      break;
    }
  }

  return true;
}