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 != _ScaleState.ready);
  bool didChangeConfiguration = false;
  bool shouldStartIfAccepted = false;
  if (event is PointerMoveEvent) {
    final VelocityTracker tracker = _velocityTrackers[event.pointer]!;
    if (!event.synthesized) {
      tracker.addPosition(event.timeStamp, event.position);
    }
    _pointerLocations[event.pointer] = event.position;
    shouldStartIfAccepted = true;
    _lastTransform = event.transform;
  } else if (event is PointerDownEvent) {
    _pointerLocations[event.pointer] = event.position;
    _pointerQueue.add(event.pointer);
    didChangeConfiguration = true;
    shouldStartIfAccepted = true;
    _lastTransform = event.transform;
  } else if (event is PointerUpEvent || event is PointerCancelEvent) {
    _pointerLocations.remove(event.pointer);
    _pointerQueue.remove(event.pointer);
    didChangeConfiguration = true;
    _lastTransform = event.transform;
  } else if (event is PointerPanZoomStartEvent) {
    assert(_pointerPanZooms[event.pointer] == null);
    _pointerPanZooms[event.pointer] = _PointerPanZoomData.fromStartEvent(this, event);
    didChangeConfiguration = true;
    shouldStartIfAccepted = true;
    _lastTransform = event.transform;
  } else if (event is PointerPanZoomUpdateEvent) {
    assert(_pointerPanZooms[event.pointer] != null);
    if (!event.synthesized && !trackpadScrollCausesScale) {
      _velocityTrackers[event.pointer]!.addPosition(event.timeStamp, event.pan);
    }
    _pointerPanZooms[event.pointer] = _PointerPanZoomData.fromUpdateEvent(this, event);
    _lastTransform = event.transform;
    shouldStartIfAccepted = true;
  } else if (event is PointerPanZoomEndEvent) {
    assert(_pointerPanZooms[event.pointer] != null);
    _pointerPanZooms.remove(event.pointer);
    didChangeConfiguration = true;
  }

  _updateLines();
  _update();

  if (!didChangeConfiguration || _reconfigure(event.pointer)) {
    _advanceStateMachine(shouldStartIfAccepted, event);
  }
  stopTrackingIfPointerNoLongerDown(event);
}