handleEvent method Null safety

  1. @override
void handleEvent(
  1. PointerEvent event,
  2. covariant HitTestEntry<HitTestTarget> entry
)
override

Override this method to handle pointer events that hit this render object.

For RenderBox objects, the entry argument is a BoxHitTestEntry. From this object you can determine the PointerDownEvent's position in local coordinates. (This is useful because PointerEvent.position is in global coordinates.)

Implementations of this method should call debugHandleEvent as follows, so that they support debugPaintPointersEnabled:

@override
void handleEvent(PointerEvent event, HitTestEntry entry) {
  assert(debugHandleEvent(event, entry));
  // ... handle the event ...
}

Implementation

@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);
  }
}