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.)

If you override this, consider calling debugHandleEvent as follows, so that you can support debugPaintPointersEnabled:

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

Implementation

@override
void handleEvent(PointerEvent event, BoxHitTestEntry entry) {
  assert(debugHandleEvent(event, entry));
  if (event is! PointerDownEvent)
    return;
  _layoutTextWithConstraints(constraints);
  final Offset offset = entry.localPosition;
  final TextPosition position = _textPainter.getPositionForOffset(offset);
  final InlineSpan span = _textPainter.text.getSpanForPosition(position);
  if (span == null) {
    return;
  }
  if (span is TextSpan) {
    final TextSpan textSpan = span;
    textSpan.recognizer?.addPointer(event as PointerDownEvent);
  }
}