handleScaleEnd method

void handleScaleEnd(
  1. ScaleEndDetails details
)

Implementation

void handleScaleEnd(ScaleEndDetails details) {
  if (extendedImageSlidePageState != null &&
      extendedImageSlidePageState!.isSliding) {
    extendedImageSlidePageState!.endSlide(details);
    return;
  }

  if (_pageViewState != null && _pageViewState!.isDraging) {
    _pageViewState!.onDragEnd(DragEndDetails(
      velocity: details.velocity,
      primaryVelocity:
          _pageViewState!.widget.scrollDirection == Axis.horizontal
              ? details.velocity.pixelsPerSecond.dx
              : details.velocity.pixelsPerSecond.dy,
    ));
    return;
  }

  //animate back to maxScale if gesture exceeded the maxScale specified
  if (_gestureDetails!.totalScale!.greaterThan(_gestureConfig!.maxScale)) {
    final double velocity =
        (_gestureDetails!.totalScale! - _gestureConfig!.maxScale) /
            _gestureConfig!.maxScale;

    _gestureAnimation.animationScale(
        _gestureDetails!.totalScale, _gestureConfig!.maxScale, velocity);
    return;
  }

  //animate back to minScale if gesture fell smaller than the minScale specified
  if (_gestureDetails!.totalScale!.lessThan(_gestureConfig!.minScale)) {
    final double velocity =
        (_gestureConfig!.minScale - _gestureDetails!.totalScale!) /
            _gestureConfig!.minScale;

    _gestureAnimation.animationScale(
        _gestureDetails!.totalScale, _gestureConfig!.minScale, velocity);
    return;
  }

  if (_gestureDetails!.actionType == ActionType.pan) {
    // get magnitude from gesture velocity
    final double magnitude = details.velocity.pixelsPerSecond.distance;

    // do a significant magnitude
    if (magnitude.greaterThanOrEqualTo(minMagnitude)) {
      final Offset direction = details.velocity.pixelsPerSecond /
          magnitude *
          _gestureConfig!.inertialSpeed;

      _gestureAnimation.animationOffset(
          _gestureDetails!.offset, _gestureDetails!.offset! + direction);
    }
  }
}