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 != _ForceState.ready);
  // A static pointer with changes in pressure creates PointerMoveEvent events.
  if (event is PointerMoveEvent || event is PointerDownEvent) {
    final double pressure = interpolation(event.pressureMin, event.pressureMax, event.pressure);
    assert(
      (pressure >= 0.0 && pressure <= 1.0) || // Interpolated pressure must be between 1.0 and 0.0...
      pressure.isNaN, // and interpolation may return NaN for values it doesn't want to support...
    );

    _lastPosition = OffsetPair.fromEventPosition(event);
    _lastPressure = pressure;

    if (_state == _ForceState.possible) {
      if (pressure > startPressure) {
        _state = _ForceState.started;
        resolve(GestureDisposition.accepted);
      } else if (event.delta.distanceSquared > computeHitSlop(event.kind, gestureSettings)) {
        resolve(GestureDisposition.rejected);
      }
    }
    // In case this is the only gesture detector we still don't want to start
    // the gesture until the pressure is greater than the startPressure.
    if (pressure > startPressure && _state == _ForceState.accepted) {
      _state = _ForceState.started;
      if (onStart != null) {
        invokeCallback<void>('onStart', () => onStart!(ForcePressDetails(
          pressure: pressure,
          globalPosition: _lastPosition.global,
          localPosition: _lastPosition.local,
        )));
      }
    }
    if (onPeak != null && pressure > peakPressure &&
       (_state == _ForceState.started)) {
      _state = _ForceState.peaked;
      if (onPeak != null) {
        invokeCallback<void>('onPeak', () => onPeak!(ForcePressDetails(
          pressure: pressure,
          globalPosition: event.position,
          localPosition: event.localPosition,
        )));
      }
    }
    if (onUpdate != null &&  !pressure.isNaN &&
       (_state == _ForceState.started || _state == _ForceState.peaked)) {
      if (onUpdate != null) {
        invokeCallback<void>('onUpdate', () => onUpdate!(ForcePressDetails(
          pressure: pressure,
          globalPosition: event.position,
          localPosition: event.localPosition,
        )));
      }
    }
  }
  stopTrackingIfPointerNoLongerDown(event);
}