/// A RenderProxyBox subclass that allows you to customize the /// hit-testing behavior. abstract class RenderProxyBoxWithHitTestBehavior extends RenderProxyBox{
bool defaultHitTestChildren(BoxHitTestResult result, { required Offset position }) { ChildType? child = lastChild; while (child != null) { // The x, y parameters have the top left of the node's box as the origin. final ParentDataType childParentData = child.parentData! as ParentDataType; final bool isHit = result.addWithPaintOffset( offset: childParentData.offset, position: position, hitTest: (BoxHitTestResult result, Offset transformed) { assert(transformed == position - childParentData.offset); return child!.hitTest(result, position: transformed); }, ); if (isHit) { return true; } child = childParentData.previousSibling; } return false; }
@override void handleEvent(PointerEvent event, HitTestEntry entry) { assert(debugHandleEvent(event, entry)); if (event is PointerDownEvent) { return onPointerDown?.call(event); } if (event is PointerMoveEvent) { return onPointerMove?.call(event); } if (event is PointerUpEvent) { return onPointerUp?.call(event); } if (event is PointerHoverEvent) { return onPointerHover?.call(event); } if (event is PointerCancelEvent) { return onPointerCancel?.call(event); } if (event is PointerPanZoomStartEvent) { return onPointerPanZoomStart?.call(event); } if (event is PointerPanZoomUpdateEvent) { return onPointerPanZoomUpdate?.call(event); } if (event is PointerPanZoomEndEvent) { return onPointerPanZoomEnd?.call(event); } if (event is PointerSignalEvent) { return onPointerSignal?.call(event); } }