onDragEnd method

void onDragEnd(
  1. DragEndDetails details
)

Updates the animation according to the DragEndDetails details of a GestureDragEndCallback

Implementation

void onDragEnd(DragEndDetails details) {
  if (dragLength == null) return;
  double minFlingVelocity = 365.0;

  // Let the current animation finish before starting a new one
  if (_animationController.isAnimating) return;

  // Check if the velocity is sufficient to constitute fling
  if (details.velocity.pixelsPerSecond.dy.abs() >= minFlingVelocity) {
    double visualVelocity =
        -details.velocity.pixelsPerSecond.dy / dragLength!;

    if (snap) {
      _animationController.fling(velocity: visualVelocity);
    } else {
      // actual scroll physics will be implemented in a future release
      _animationController.animateTo(
        _animationController.value + visualVelocity * 0.16,
        duration: Duration(milliseconds: 410),
        curve: Curves.decelerate,
      );
    }
    return;
  }

  // Check if the controller is already halfway there
  if (snap) {
    if (_animationController.value > 0.5)
      open();
    else
      close();
  }
}