handleEvent method

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

Called when a pointer event is routed to this recognizer.

This will be called for every pointer event while the pointer is being tracked. Typically, this recognizer will start tracking the pointer in addAllowedPointer, which means that handleEvent will be called starting with the PointerDownEvent that was passed to addAllowedPointer.

See also:

Implementation

@override
void handleEvent(PointerEvent event) {
  assert(_state != _DragState.ready);
  if (!event.synthesized &&
      (event is PointerDownEvent ||
       event is PointerMoveEvent ||
       event is PointerPanZoomStartEvent ||
       event is PointerPanZoomUpdateEvent)) {
    final Offset position = switch (event) {
      PointerPanZoomStartEvent() => Offset.zero,
      PointerPanZoomUpdateEvent() => event.pan,
      _ => event.localPosition,
    };
    _velocityTrackers[event.pointer]!.addPosition(event.timeStamp, position);
  }
  if (event is PointerMoveEvent && event.buttons != _initialButtons) {
    _giveUpPointer(event.pointer);
    return;
  }
  if ((event is PointerMoveEvent || event is PointerPanZoomUpdateEvent)
      && _shouldTrackMoveEvent(event.pointer)) {
    final Offset delta = (event is PointerMoveEvent) ? event.delta : (event as PointerPanZoomUpdateEvent).panDelta;
    final Offset localDelta = (event is PointerMoveEvent) ? event.localDelta : (event as PointerPanZoomUpdateEvent).localPanDelta;
    final Offset position = (event is PointerMoveEvent) ? event.position : (event.position + (event as PointerPanZoomUpdateEvent).pan);
    final Offset localPosition = (event is PointerMoveEvent) ? event.localPosition : (event.localPosition + (event as PointerPanZoomUpdateEvent).localPan);
    _finalPosition = OffsetPair(local: localPosition, global: position);
    final Offset resolvedDelta = _resolveLocalDeltaForMultitouch(event.pointer, localDelta);
    switch (_state) {
      case _DragState.ready || _DragState.possible:
        _pendingDragOffset += OffsetPair(local: localDelta, global: delta);
        _lastPendingEventTimestamp = event.timeStamp;
        _lastTransform = event.transform;
        final Offset movedLocally = _getDeltaForDetails(localDelta);
        final Matrix4? localToGlobalTransform = event.transform == null ? null : Matrix4.tryInvert(event.transform!);
        _globalDistanceMoved += PointerEvent.transformDeltaViaPositions(
          transform: localToGlobalTransform,
          untransformedDelta: movedLocally,
          untransformedEndPosition: localPosition
        ).distance * (_getPrimaryValueFromOffset(movedLocally) ?? 1).sign;
        if (_hasSufficientGlobalDistanceToAccept(event.kind, gestureSettings?.touchSlop)) {
          _hasDragThresholdBeenMet = true;
          if (_acceptedActivePointers.contains(event.pointer)) {
            _checkDrag(event.pointer);
          } else {
            resolve(GestureDisposition.accepted);
          }
        }
      case _DragState.accepted:
        _checkUpdate(
          sourceTimeStamp: event.timeStamp,
          delta: _getDeltaForDetails(resolvedDelta),
          primaryDelta: _getPrimaryValueFromOffset(resolvedDelta),
          globalPosition: position,
          localPosition: localPosition,
        );
    }
    _recordMoveDeltaForMultitouch(event.pointer, localDelta);
  }
  if (event case PointerUpEvent() || PointerCancelEvent() || PointerPanZoomEndEvent()) {
    _giveUpPointer(event.pointer);
  }
}