handlePointerEvent method

  1. @override
void handlePointerEvent(
  1. PointerEvent event
)
override

Dispatch an event to the targets found by a hit test on its position.

If the pointerEventSource is TestBindingEventSource.test, then the event is forwarded to GestureBinding.dispatchEvent as usual; additionally, down pointers are painted on the screen.

If the pointerEventSource is TestBindingEventSource.device, then the event, after being transformed to the local coordinate system, is forwarded to deviceEventDispatcher.

Implementation

@override
void handlePointerEvent(PointerEvent event) {
  switch (pointerEventSource) {
    case TestBindingEventSource.test:
      RenderView? target;
      for (final RenderView renderView in renderViews) {
        if (renderView.flutterView.viewId == event.viewId) {
          target = renderView;
          break;
        }
      }
      if (target != null) {
        final _LiveTestPointerRecord? record = _renderViewToPointerIdToPointerRecord[target]?[event.pointer];
        if (record != null) {
          record.position = event.position;
          if (!event.down) {
            record.decay = _kPointerDecay;
          }
          _markViewsNeedPaint(event.viewId);
        } else if (event.down) {
          _renderViewToPointerIdToPointerRecord[target] ??= <int, _LiveTestPointerRecord>{};
          _renderViewToPointerIdToPointerRecord[target]![event.pointer] = _LiveTestPointerRecord(
            event.pointer,
            event.position,
          );
          _markViewsNeedPaint(event.viewId);
        }
      }
      super.handlePointerEvent(event);
    case TestBindingEventSource.device:
      if (shouldPropagateDevicePointerEvents) {
        super.handlePointerEvent(event);
        break;
      }
      if (deviceEventDispatcher != null) {
        // The pointer events received with this source has a global position
        // (see [handlePointerEventForSource]). Transform it to the local
        // coordinate space used by the testing widgets.
        final RenderView renderView = renderViews.firstWhere((RenderView r) => r.flutterView.viewId == event.viewId);
        final PointerEvent localEvent = event.copyWith(position: globalToLocal(event.position, renderView));
        withPointerEventSource(TestBindingEventSource.device,
          () => super.handlePointerEvent(localEvent)
        );
      }
  }
}