handleEvent method

  1. @override
void handleEvent (PointerEvent event)
override

Called when a pointer event is routed to this recognizer.

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) {
    if (event.pressure > event.pressureMax || event.pressure < event.pressureMin) {
      debugPrint(
        'The reported device pressure ' + event.pressure.toString() +
        ' is outside of the device pressure range where: ' +
        event.pressureMin.toString() + ' <= pressure <= ' + event.pressureMax.toString(),
      );
    }

    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 > kTouchSlop) {
        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);
}