dispatchEvent method

  1. @override
void dispatchEvent(
  1. PointerEvent event,
  2. HitTestResult? hitTestResult
)
override

Dispatch an event to pointerRouter and the path of a hit test result.

The event is routed to pointerRouter. If the hitTestResult is not null, the event is also sent to every HitTestTarget in the entries of the given HitTestResult. Any exceptions from the handlers are caught.

The hitTestResult argument may only be null for PointerAddedEvents or PointerRemovedEvents.

Implementation

@override // from HitTestDispatcher
@pragma('vm:notify-debugger-on-exception')
void dispatchEvent(PointerEvent event, HitTestResult? hitTestResult) {
  assert(!locked);
  // No hit test information implies that this is a [PointerAddedEvent] or
  // [PointerRemovedEvent]. These events are specially routed here; other
  // events will be routed through the `handleEvent` below.
  if (hitTestResult == null) {
    assert(event is PointerAddedEvent || event is PointerRemovedEvent);
    try {
      pointerRouter.route(event);
    } catch (exception, stack) {
      FlutterError.reportError(FlutterErrorDetailsForPointerEventDispatcher(
        exception: exception,
        stack: stack,
        library: 'gesture library',
        context: ErrorDescription('while dispatching a non-hit-tested pointer event'),
        event: event,
        informationCollector: () => <DiagnosticsNode>[
          DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty),
        ],
      ));
    }
    return;
  }
  for (final HitTestEntry entry in hitTestResult.path) {
    try {
      entry.target.handleEvent(event.transformed(entry.transform), entry);
    } catch (exception, stack) {
      FlutterError.reportError(FlutterErrorDetailsForPointerEventDispatcher(
        exception: exception,
        stack: stack,
        library: 'gesture library',
        context: ErrorDescription('while dispatching a pointer event'),
        event: event,
        hitTestEntry: entry,
        informationCollector: () => <DiagnosticsNode>[
          DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty),
          DiagnosticsProperty<HitTestTarget>('Target', entry.target, style: DiagnosticsTreeStyle.errorProperty),
        ],
      ));
    }
  }
}