didStopTrackingLastPointer method

  1. @override
void didStopTrackingLastPointer (int pointer)
override

Called when the number of pointers this recognizer is tracking changes from one to zero.

The given pointer ID is the ID of the last pointer this recognizer was tracking.

Implementation

@override
void didStopTrackingLastPointer(int pointer) {
  if (_state == _DragState.possible) {
    resolve(GestureDisposition.rejected);
    _state = _DragState.ready;
    if (onCancel != null)
      invokeCallback<void>('onCancel', onCancel);
    return;
  }
  final bool wasAccepted = _state == _DragState.accepted;
  _state = _DragState.ready;
  if (wasAccepted && onEnd != null) {
    final VelocityTracker tracker = _velocityTrackers[pointer];
    assert(tracker != null);

    final VelocityEstimate estimate = tracker.getVelocityEstimate();
    if (estimate != null && _isFlingGesture(estimate)) {
      final Velocity velocity = Velocity(pixelsPerSecond: estimate.pixelsPerSecond)
        .clampMagnitude(minFlingVelocity ?? kMinFlingVelocity, maxFlingVelocity ?? kMaxFlingVelocity);
      invokeCallback<void>('onEnd', () => onEnd(DragEndDetails(
        velocity: velocity,
        primaryVelocity: _getPrimaryValueFromOffset(velocity.pixelsPerSecond),
      )), debugReport: () {
        return '$estimate; fling at $velocity.';
      });
    } else {
      invokeCallback<void>('onEnd', () => onEnd(DragEndDetails(
        velocity: Velocity.zero,
        primaryVelocity: 0.0,
      )), debugReport: () {
        if (estimate == null)
          return 'Could not estimate velocity.';
        return '$estimate; judged to not be a fling.';
      });
    }
  }
  _velocityTrackers.clear();
}