endDrag method

void endDrag(
  1. Offset velocityPerSecond, {
  2. bool? commit,
})

Releases the finger. The displacement always springs back to zero with the carried velocity; whether the close flight plays too is decided by momentum projection (morphProjectValue per axis) against morphDragCommitDistance / morphDragCommitVelocity - or forced either way with commit.

Implementation

void endDrag(Offset velocityPerSecond, {bool? commit}) {
  if (_finished || !_drag.isActive) {
    return;
  }
  final Offset offset = _drag.offset;
  final Offset projected = Offset(
    morphProjectValue(offset.dx, velocityPerSecond.dx),
    morphProjectValue(offset.dy, velocityPerSecond.dy),
  );
  final bool shouldClose =
      commit ??
      (projected.distance > morphDragCommitDistance ||
          velocityPerSecond.distance > morphDragCommitVelocity);
  _drag.release(velocityPerSecond);
  if (shouldClose && isOpenOrOpening) {
    close();
  }
}