handleEvent method

  1. @override
void handleEvent(
  1. PointerEvent event,
  2. covariant BoxHitTestEntry 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:

class RenderFoo extends RenderBox {
  // ...

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

  // ...
}

Implementation

@override
void handleEvent(PointerEvent event, covariant BoxHitTestEntry entry) {
  if (!_interactive) return;
  final at = event.localPosition;
  final mouse = event.kind == PointerDeviceKind.mouse;
  if (event is PointerSignalEvent) {
    if (event is PointerScrollEvent && _on.wheelZoom && _movable) {
      GestureBinding.instance.pointerSignalResolver.register(event, (e) => _signal(e as PointerScrollEvent));
    }
  } else if (event is PointerHoverEvent) {
    if (_hover) engine.setCursor(at);
    engine.hover(at);
  } else if (event is PointerDownEvent) {
    _fling.stop();
    // Only the gestures the spec gives the graph: a graph that neither
    // pans nor pins leaves a drag to the page it is on.
    if (_rect && (_on.dragPan || _on.pinchZoom || _on.axisScale)) _scaleGesture.addPointer(event);
    if (_rect && _on.doubleTapReset) _doubleTapGesture.addPointer(event);
    if (_select.tap) _tapGesture.addPointer(event);
    if (_press && engine.spec.crosshair.enabled) _longPressGesture.addPointer(event);
    // A scrub: the cursor is under the finger from the moment it is down.
    if (_touch) engine.setCursor(at);
    // A finger selects from the moment it is down, as a pointer over it
    // does; lifting it lets go (a tap, where taps pin, then pins).
    if (!mouse) engine.hover(at);
  } else if (event is PointerMoveEvent) {
    // A mouse with its button down sends no hover: the crosshair and the
    // selection follow it through a drag all the same.
    if (_touch || (_hover && mouse)) engine.setCursor(at);
    engine.hover(at);
  } else if (event is PointerUpEvent || event is PointerCancelEvent) {
    if (_touch && !mouse) engine.setCursor(null);
    if (!mouse) engine.hover(null);
  }
}