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 VelocityTracker tracker = _velocityTrackers[event.pointer]!;
    if (event is PointerPanZoomStartEvent) {
      tracker.addPosition(event.timeStamp, Offset.zero);
    } else if (event is PointerPanZoomUpdateEvent) {
      tracker.addPosition(event.timeStamp, event.pan);
    } else {
      tracker.addPosition(event.timeStamp, event.localPosition);
    }
  }
  if (event is PointerDownEvent || event is PointerPanZoomStartEvent) {
    final Duration? timestamp = _lastPendingEventTimestamp;
    _checkStart(timestamp!, event.pointer);
  }
  if (event is PointerMoveEvent && event.buttons != _initialButtons) {
    _giveUpPointer(event.pointer);
    return;
  }
  if (event is PointerMoveEvent || event is PointerPanZoomUpdateEvent) {
    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);

    if (_state == _DragState.accepted) {
      _checkUpdate(
        sourceTimeStamp: event.timeStamp,
        delta: _getDeltaForDetails(localDelta),
        primaryDelta: _getPrimaryValueFromOffset(localDelta),
        globalPosition: position,
        localPosition: localPosition,
      );
    } else {
      _pendingDragOffset = _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)).sign;
      if (_hasSufficientGlobalDistanceToAccept(event.kind) && _acceptDragGesture(event))
        resolve(GestureDisposition.accepted);
    }
  }
  if (event is PointerUpEvent || event is PointerCancelEvent || event is PointerPanZoomEndEvent) {
    _giveUpPointer(
      event.pointer,
      reject: event is PointerCancelEvent || _state == _DragState.possible,
    );
  }
}