The ExpandableAnimation widget

ExpandableAnimation shows its child in place. When expanded, the child is hidden in place (keeping its size), and a morphing surface animates from the child's bounds to the expanded bounds while the collapsed and expanded content cross-fade.

ParameterDefaultPurpose
childrequiredThe widget shown in place.
expandedBuilderrequiredBuilds the expanded view.
tagnullReconnects the view to a rebuilt source with the same tag.
controllerinternalExpand and collapse from code; observe state.
modefullscreen()Where the view expands to.
duration / reverseDuration400 ms / sameTime-based motion.
curve / reverseCurveeaseInOutCubic / sameEasing.
physicsnullSpring motion; overrides duration and curve.
borderRadius / expandedBorderRadiussquareCorner radius at each end.
collapsedColor / expandedColortransparentSurface color at each end.
backgroundColor, backgroundOpacityblack, 0.5Scrim behind the expanded view.
backgroundBlur0Blur sigma behind the view (costly).
dismissOnBackgroundTaptrueTap outside to close (dialog and sheet modes).
enableDragToDismiss, gestureConfigtrue, defaultsInteractive dismissal.
expandOnTap, enabledtrue, trueTap trigger and global enable switch.
hideSourceWhileExpandedtrueHide the child in place while expanded.
useRootNavigatortrueCover bottom bars and nested navigators.
respectReducedMotiontrueInstant transitions when the OS asks for less motion.
transitionBuildercross-fadeCompose the collapsed and expanded layers.
hoverScale1.0 (off)Lift on mouse hover and keyboard focus.
semanticLabel, backgroundSemanticLabelnull, 'Close'Screen reader labels.
onExpanded, onCollapsed, onPhaseChanged—Lifecycle callbacks.

Expansion modes

// Fill the screen (default). useSafeArea stops at notches and system bars.
const ExpandableAnimationMode.fullscreen(useSafeArea: false)

// A centered panel: inset by margin, capped at maxSize, above the keyboard.
const ExpandableAnimationMode.dialog(
  margin: EdgeInsets.all(24),
  maxSize: Size(560, 720),
)

// Partial expansion anchored to the bottom edge.
const ExpandableAnimationMode.sheet(heightFactor: 0.6, maxWidth: 640)

// Anything else: compute a Rect from the overlay size, safe area,
// keyboard insets and the source bounds.
ExpandableAnimationMode.custom(
  (bounds) => Alignment.topRight.inscribe(
    const Size(360, 480),
    bounds.safeArea.deflate(16),
  ),
)

The expanded bounds are recomputed on every layout, so they follow window resizes and orientation changes. The source bounds are measured again when collapsing, so the view returns to wherever the child is now.

Controller and lifecycle

final controller = ExpandableAnimationController();

await controller.expand();   // completes when expanded or interrupted
await controller.collapse(); // completes when collapsed or interrupted
controller.toggle();

controller.phase;       // ExpandableAnimationPhase.collapsed / expanding / expanded / collapsing
controller.progress;    // 0.0 – 1.0
controller.isDragging;  // true during a dismiss drag
controller.isAttached;  // attached to a mounted widget

// Dispose it in the State that created it.
controller.dispose();

Without a controller, the widget creates one. Read it from either subtree with ExpandableAnimation.of(context). Interruptions reverse from the current position: collapse() during an expansion, or expand() (or a tap) during a collapse.

Duration, curves and spring physics

ExpandableAnimation(
  duration: const Duration(milliseconds: 450),
  curve: Curves.easeOutCubic,
  reverseCurve: Curves.easeInCubic,
  // ...or a spring, which replaces both:
  physics: const ExpandableAnimationPhysics.spring(
    stiffness: 200,
    dampingRatio: 0.75, // below 1.0 overshoots
  ),
  // ...
)

Presets: ExpandableAnimationPhysics.smooth (no overshoot), bouncy and snappy. The collapse always uses a critically damped version of the spring so the view never shrinks past its source. SpringCurve is exported too, if you want spring-shaped curves elsewhere.

Drag-to-dismiss and gestures

See the dedicated drag-to-dismiss guide. In short: drag down to dismiss; vertical scrollables scroll until they reach the top; PopScope can veto; thresholds live in ExpandableAnimationGestureConfig. Set dismissDirections to any combination of down, up, left and right.

A drag that dismisses the view hands its speed to the collapse (matchReleaseVelocity, on by default). For zoomable content such as photos, wrap it in ExpandableAnimationZoomable: pinch, pan and double-tap zoom that pause dismissal while zoomed in. See the fullscreen image guide.

Shared element slots

Wrap an element in ExpandableAnimationSlot(tag: ...) in both the collapsed child and the expanded view. During the transition it flies between its two positions on its own path. See the shared element transition guide.

App-wide defaults

Every parameter in the table above except child, expandedBuilder, controller, callbacks and labels is optional. Leave it out and the value comes from the nearest ExpandableAnimationTheme, then from the default shown above:

ExpandableAnimationTheme(
  data: const ExpandableAnimationThemeData(
    physics: ExpandableAnimationPhysics.snappy,
    borderRadius: BorderRadius.all(Radius.circular(20)),
    gestureConfig: ExpandableAnimationGestureConfig(
      dismissDirections: {
        ExpandableAnimationDismissDirection.down,
        ExpandableAnimationDismissDirection.up,
      },
    ),
    hoverScale: 1.02,
  ),
  child: MaterialApp(home: const HomePage()),
)

Widget values always win over the theme. The theme is an InheritedTheme, so it also applies inside expanded views.

Custom transitions

The transitionBuilder receives the clamped progress animation and the two layers. Each layer fills the surface, laid out at its natural size and scaled to the surface width:

ExpandableAnimation(
  transitionBuilder: (context, animation, collapsed, expanded) {
    return Stack(
      fit: StackFit.expand,
      children: [
        FadeTransition(
          opacity: ReverseAnimation(CurvedAnimation(
            parent: animation,
            curve: const Interval(0, 0.3),
          )),
          child: collapsed,
        ),
        FadeTransition(
          opacity: CurvedAnimation(
            parent: animation,
            curve: const Interval(0.3, 0.7),
          ),
          child: expanded,
        ),
      ],
    );
  },
  // ...
)
  • The expanded view is a modal route on the root navigator, so it covers bottom navigation bars. The back button, Escape and Navigator.pop collapse it.
  • Nested navigators: with useRootNavigator: false the view opens inside the nearest navigator, such as a tab's, and the bar stays visible. For the system back button to reach a nested navigator, wrap it in NavigatorPopHandler, as with any nested navigator.
  • Android predictive back: with android:enableOnBackInvokedCallback="true", a completed back gesture collapses the view and a cancelled one leaves it open. The view does not follow the finger during the gesture (no predictive preview), and a PopScope inside it can still veto the pop.
  • Inherited themes (Theme, CupertinoTheme, IconTheme, DefaultTextStyle and others) are captured at the source and applied to the expanded view.
  • The child and the expanded content are separate widget instances. Keep shared state, such as music playback, outside both — see the music player example.
  • Rebuilding the parent rebuilds the expanded view with the new expandedBuilder.
  • If the child is removed while expanded, the controller keeps working and the view fades out in place when collapsed — unless a new ExpandableAnimation with the same tag appeared, in which case the view collapses into it.

Accessibility

  • The child is a focusable button activated by tap, Enter or Space; set semanticLabel.
  • Focus moves into the expanded view and returns afterwards; screen readers get a dismiss action.
  • Content is not interactive and hidden from screen readers until the expansion finishes.
  • Reduced motion makes transitions instant when respectReducedMotion is on.

Performance

  • Both layers keep fixed constraints while the surface animates, so their subtrees are not re-laid out every frame; only a scale transform changes.
  • The collapsed copy stops painting after the expansion finishes.
  • backgroundBlur is the most expensive option; it is off by default. The blur keeps a constant radius and fades in with opacity, which is cheaper than animating the radius.
  • Measured profile-mode frame times for iPhone 12, a Snapdragon 765G Android phone and an M1 Pro MacBook Pro are on the Benchmarks page.

Known limitations

  • A plain InteractiveViewer competes with drag-to-dismiss; use ExpandableAnimationZoomable instead.
  • Inherited widgets other than themes are not carried into the expanded view.
  • The expanded view is not a Material. Widgets that need one, such as ListTile or InkWell, must be inside a Material or Scaffold in expandedBuilder.