dispatchEvent method

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

Dispatch an event to a hit test result's path.

This sends the given event to every HitTestTarget in the entries of the given HitTestResult, and catches exceptions that any of the handlers might throw. The hitTestResult argument may only be null for PointerHoverEvent, PointerAddedEvent, or PointerRemovedEvent events.

Implementation

@override // from HitTestDispatcher
void dispatchEvent(PointerEvent event, HitTestResult hitTestResult) {
  assert(!locked);
  // No hit test information implies that this is a hover or pointer
  // add/remove event.
  if (hitTestResult == null) {
    assert(event is PointerHoverEvent || 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,
        hitTestEntry: null,
        informationCollector: () sync* {
          yield DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
        },
      ));
    }
    return;
  }
  for (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: () sync* {
          yield DiagnosticsProperty<PointerEvent>('Event', event, style: DiagnosticsTreeStyle.errorProperty);
          yield DiagnosticsProperty<HitTestTarget>('Target', entry.target, style: DiagnosticsTreeStyle.errorProperty);
        },
      ));
    }
  }
}