Flutter drag-to-dismiss animation on a fullscreen page
Dragging a fullscreen page down to dismiss it

Drag-to-dismiss lets users close a fullscreen view the way they opened it: directly, with their finger. It is on by default in ExpandableAnimation.

How the gesture works

  1. The user drags the expanded view downward. It follows the finger (scaled by dragResistance), shrinks toward minScale, rounds its corners and the background fades.
  2. On release it dismisses if it was dragged at least dismissThreshold × its height, or flung downward faster than velocityThreshold.
  3. Otherwise it springs back, carrying the release velocity. A fast upward fling always cancels.
  4. When it dismisses, the collapse starts from exactly where the finger left it, at the speed the finger was moving (set matchReleaseVelocity: false to use the plain reverse animation).
ExpandableAnimation(
  enableDragToDismiss: true,
  gestureConfig: const ExpandableAnimationGestureConfig(
    dismissThreshold: 0.2,
    velocityThreshold: 700,
    minScale: 0.85,
    dragResistance: 0.6,
    enableHapticFeedback: true,
    matchReleaseVelocity: true,
  ),
  expandedBuilder: (context) => const DetailsPage(),
  child: const SummaryCard(),
)

An interactive page transition

A regular Flutter page route plays its transition from start to finish once it begins. Here the dismissal is an interactive page transition: the finger drives the expanded view directly, frame by frame, and can pull it back the other way at any time. Nothing is decided until release.

  • Follows the finger: the drag offset, scale, corner radius and background fade are computed from the current drag on every frame.
  • Reversible: dragging back toward the start restores the full view; an upward fling cancels.
  • Continuous on release: the collapse continues from the dragged position at the finger's speed instead of restarting a fixed animation.
  • Interruptible: calling controller.expand() during a collapse (or collapse() during an expansion) reverses from the current position.
  • Observable: controller.progress and controller.isDragging report the gesture, so other widgets can react (see below).

The same expanded view is a real route, so the back button, Escape and PopScope keep working alongside the gesture.

Directions

Dismissal is downward by default. Allow any combination of directions:

gestureConfig: const ExpandableAnimationGestureConfig(
  dismissDirections: {
    ExpandableAnimationDismissDirection.down,
    ExpandableAnimationDismissDirection.up,
    ExpandableAnimationDismissDirection.left,
    ExpandableAnimationDismissDirection.right,
  },
),

Each drag locks to the axis it starts on. The surface shrinks away from the edge it leaves, so a rightward drag anchors at the left edge and slides right.

Scrollable content

Vertical lists inside the expanded view keep scrolling normally. The dismiss gesture only starts when a list that is already at its top is pulled further down, and it hands control back if the user drags up again. Horizontal scrollables, such as a PageView, are only involved when left or right is allowed: then swiping past the first or last page dismisses. Set dismissFromScrollableContent: false to dismiss only from non-scrolling areas.

Preventing a dismissal

PopScope(
  canPop: !hasUnsavedChanges,
  onPopInvokedWithResult: (didPop, result) {
    if (!didPop) showDiscardDialog(context);
  },
  child: const EditForm(),
)

With canPop: false, drags spring back and background taps, Escape and the back button are ignored; controller.collapse() still works.

Observing the drag

ListenableBuilder(
  listenable: controller,
  builder: (context, _) => Opacity(
    opacity: controller.isDragging ? controller.progress : 1,
    child: const Toolbar(),
  ),
)

Try it

Change the thresholds in the playground, or drag the article cards and the music player. Related: iOS-style animations.