Expandable Animation — Flutter Widget to Fullscreen Animations

Expand any widget. Animate every transition.

pub package CI License: MIT

Expandable Animation is a Flutter package for widget-to-fullscreen transitions, expandable card animations and interactive container morphing. Wrap any widget, give it an expanded view, and the package morphs its position, size, corner radius and color into a fullscreen page, a dialog or a bottom sheet — with spring physics, drag-to-dismiss and a smooth reverse animation back into place.

It is not an accordion or an ExpansionTile replacement: it turns a widget into a separate, larger experience, like the cards in an app store, a mini music player or a photo thumbnail.

Live demo · Documentation · API reference

Flutter card to fullscreen animation with drag-to-dismiss Flutter expandable music player animation Flutter App Store-style card animation

Flutter fullscreen image transition from a gallery thumbnail Flutter widget expanding into a bottom sheet

The animations above are rendered frame by frame from the example app with ./scripts/record_media.sh.

Why use Expandable Animation?

Building a card-to-fullscreen transition by hand usually means combining a custom PageRoute, Hero widgets, measured RenderBox bounds, a gesture recognizer for dismissal and scroll coordination. This package packages that into one wrapper:

  • One widget. Wrap the collapsed widget, return the expanded widget from a builder. No Hero tags, no route classes.
  • Interactive dismissal. Drag the expanded view down to shrink it and send it home; scrollable content keeps scrolling until it reaches its top.
  • Interruptible. Tap again, press back or call the controller in the middle of a transition and it reverses from where it is.
  • Real navigation. The expanded view is a modal route, so the back button, Escape, PopScope, focus and screen readers work as users expect.
  • Zero dependencies. Only the Flutter SDK.

Features

  • Widget-to-fullscreen, dialog (centered panel) and sheet (partial height) expansion, plus custom bounds
  • Smooth, reversible container transform: position, size, border radius and surface color
  • Duration and curve, or spring physics with optional overshoot
  • Background scrim with configurable color, opacity and optional blur
  • Drag-to-dismiss with distance and velocity thresholds, spring settle-back, haptic feedback and scroll coordination
  • A flick hands its speed to the collapse, so fast flicks close faster
  • ExpandableAnimationZoomable: pinch, pan and double-tap zoom that cooperate with drag-to-dismiss
  • Dismiss in any combination of directions: down, up, left and right
  • App-wide defaults with ExpandableAnimationTheme
  • Shared element transitions inside the morph with ExpandableAnimationSlot
  • tag reconnects the view to a source that was rebuilt while expanded
  • Optional hover and keyboard-focus lift on desktop and web (hoverScale)
  • ExpandableAnimationController: expand(), collapse(), toggle(), phase, progress, isDragging
  • Lifecycle callbacks: onExpanded, onCollapsed, onPhaseChanged
  • Back button, Escape key, PopScope vetoes and semantics dismiss action
  • Keyboard activation (Enter/Space) and screen-reader labels
  • Reduced-motion support
  • Re-measures the source on collapse; fades out gracefully if the source is gone
  • Works with MaterialApp, CupertinoApp and WidgetsApp; inherited themes are carried into the expanded view

Installation

flutter pub add expandable_animation
import 'package:expandable_animation/expandable_animation.dart';

Quick start

ExpandableAnimation(
  borderRadius: BorderRadius.circular(20),
  expandedBuilder: (context) => const ProductDetails(),
  child: const ProductCard(),
)

Tap the card and it morphs into ProductDetails. Drag down, press back or call Navigator.pop(context) to collapse it.

Basic usage

Give the surface colors that match your widgets so the morph looks seamless:

ExpandableAnimation(
  borderRadius: BorderRadius.circular(20),
  collapsedColor: Theme.of(context).colorScheme.surfaceContainerHigh,
  expandedColor: Theme.of(context).colorScheme.surface,
  expandedBuilder: (context) => ProductDetails(product: product),
  child: ProductCard(product: product),
)

Close the expanded view from inside it:

IconButton(
  icon: const Icon(Icons.close),
  onPressed: () => ExpandableAnimation.of(context).collapse(),
)

Advanced usage

ExpandableAnimation(
  controller: controller,
  mode: const ExpandableAnimationMode.dialog(maxSize: Size(480, 640)),
  physics: ExpandableAnimationPhysics.bouncy,
  borderRadius: BorderRadius.circular(24),
  expandedBorderRadius: BorderRadius.circular(32),
  backgroundBlur: 10,
  backgroundOpacity: 0.3,
  gestureConfig: const ExpandableAnimationGestureConfig(
    dismissThreshold: 0.15,
    velocityThreshold: 600,
  ),
  onExpanded: () => debugPrint('expanded'),
  onCollapsed: () => debugPrint('collapsed'),
  expandedBuilder: (context) => const ProfileDetails(),
  child: const ProfileTile(),
)

Expansion modes

Mode Result
ExpandableAnimationMode.fullscreen() Fills the screen (default). useSafeArea: true stops at the insets.
ExpandableAnimationMode.dialog() Centered panel with a margin and maximum size; stays above the keyboard.
ExpandableAnimationMode.sheet(heightFactor: 0.6) Bottom-anchored partial expansion; rides on top of the keyboard.
ExpandableAnimationMode.custom(resolver) Any rectangle you compute from the screen size, safe area and source bounds.

Controller usage

class _ProductTileState extends State<ProductTile> {
  final controller = ExpandableAnimationController();

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return ExpandableAnimation(
      controller: controller,
      expandOnTap: false, // expand only from code
      expandedBuilder: (context) => const ProductDetails(),
      child: const ProductCard(),
    );
  }
}

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

controller.phase;      // collapsed, expanding, expanded, collapsing
controller.progress;   // 0.0 – 1.0
controller.isDragging; // true while the user drags to dismiss

The controller is a ChangeNotifier, so it can drive a ListenableBuilder. Calling collapse() during an expansion (or expand() during a collapse) reverses the transition from its current position.

Gesture configuration

ExpandableAnimation(
  enableDragToDismiss: true, // default
  gestureConfig: const ExpandableAnimationGestureConfig(
    dismissThreshold: 0.2,         // fraction of the expanded height
    velocityThreshold: 700,        // px/s; a fast fling dismisses
    minScale: 0.85,                // how far the view shrinks while dragged
    dragResistance: 0.6,           // 1.0 follows the finger exactly
    enableHapticFeedback: true,    // tick when crossing the threshold
    dismissFromScrollableContent: true,
    clampScrollPhysics: true,      // no iOS bounce competing at the top edge
    matchReleaseVelocity: true,    // a flick's speed carries into the collapse
    dismissDirections: {           // any of down, up, left, right
      ExpandableAnimationDismissDirection.down,
    },
  ),
  // ...
)

Vertical scrollables inside the expanded view scroll normally. A dismissal only starts when the user pulls down while the scrollable is at its top. Horizontal scrollables such as PageView are untouched unless left or right is allowed. A PopScope with canPop: false inside the expanded view vetoes drag, background-tap, Escape and back-button dismissals.

Each drag locks to the axis it starts on. With dismissDirections such as {down, up} or {left, right}, vertical lists dismiss when pulled past either end and a PageView dismisses when swiped past its first or last page.

When a drag dismisses the view, the collapse continues at the speed the finger left the screen and eases into place with a critically damped spring: your physics if set, otherwise one that settles in about reverseDuration.

Zoomable content

A plain InteractiveViewer claims one-finger drags, which blocks drag-to-dismiss. Use ExpandableAnimationZoomable instead:

ExpandableAnimation(
  backgroundOpacity: 1,
  expandedBuilder: (context) => ExpandableAnimationZoomable(
    maxScale: 4,
    child: Image.asset('assets/photo.jpg', fit: BoxFit.contain),
  ),
  child: Image.asset('assets/photo_thumb.jpg', fit: BoxFit.cover),
)
  • Zoomed out: a downward drag dismisses as usual.
  • Zoomed in: one finger pans the image; dismissal waits until you zoom out.
  • Two fingers always pinch-zoom; double tap zooms in around the tap and back.
  • Collapsing while zoomed (for example with back) zooms out as it shrinks.

App-wide defaults

Every visual and gesture parameter is optional. Values you leave out come from the nearest ExpandableAnimationTheme, and then from the package defaults:

ExpandableAnimationTheme(
  data: const ExpandableAnimationThemeData(
    physics: ExpandableAnimationPhysics.snappy,
    borderRadius: BorderRadius.all(Radius.circular(20)),
    backgroundBlur: 8,
    hoverScale: 1.02,
  ),
  child: MaterialApp(home: const HomePage()),
)

A parameter set on an ExpandableAnimation always wins over the theme. The theme is carried into expanded views, so nested expansions use it too.

Shared element slots

Mark an element in the collapsed child and in the expanded view with the same ExpandableAnimationSlot tag, and it flies on its own path — from its spot in the card to its spot in the page — while the rest of the container morphs around it:

ExpandableAnimation(
  expandedBuilder: (context) => Column(
    children: [
      SizedBox(
        height: 280,
        width: double.infinity,
        child: ExpandableAnimationSlot(
          tag: product.id,
          child: Image.network(product.imageUrl, fit: BoxFit.cover),
        ),
      ),
      ProductDescription(product: product),
    ],
  ),
  child: Row(
    children: [
      SizedBox.square(
        dimension: 72,
        child: ExpandableAnimationSlot(
          tag: product.id,
          borderRadius: BorderRadius.circular(12),
          child: Image.network(product.thumbnailUrl, fit: BoxFit.cover),
        ),
      ),
      ProductSummary(product: product),
    ],
  ),
)

The flying copy cross-fades from the collapsed content to the expanded content, is fitted with the slot's fit (default BoxFit.cover) and clipped to a radius that interpolates between the two slots' borderRadius. Slots fly only while the transition animates, including the collapse after a drag.

Reconnecting a rebuilt source

If the source widget is rebuilt as a new widget while its view is expanded (for example, a list item that gets a new key after a data refresh), give it a tag. The new ExpandableAnimation with the same tag stays hidden while the view is open, and the view collapses into it instead of fading out:

ExpandableAnimation(
  tag: item.id,
  expandedBuilder: (context) => ItemDetails(item: item),
  child: ItemCard(item: item),
)

Hover and focus effect

On desktop and web, hoverScale gently enlarges the collapsed widget while the mouse is over it or it has keyboard focus, hinting that it opens. It is off by default (1.0); subtle values like 1.02 work best. The expansion starts from the enlarged widget, so there is no jump.

Animation customization

  • duration, reverseDuration, curve, reverseCurve — time-based motion.
  • physics: ExpandableAnimationPhysics.spring(stiffness:, dampingRatio:) — spring motion; presets smooth, bouncy and snappy. Underdamped springs overshoot visibly on expansion; collapse is always critically damped.
  • transitionBuilder — replace the default cross-fade between the collapsed and expanded layers:
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,
        ),
      ],
    );
  },
  // ...
)

Real-world examples

The example app and the live demo include:

Public API reference

Type Purpose
ExpandableAnimation The widget. Wraps a child and builds the expanded view.
ExpandableAnimationController Expand, collapse and toggle from code; observe phase and progress.
ExpandableAnimationMode Fullscreen, dialog, sheet or custom expanded bounds.
ExpandableAnimationPhysics Spring physics for the transition.
ExpandableAnimationGestureConfig Drag-to-dismiss thresholds and behavior.
ExpandableAnimationPhase collapsed, expanding, expanded, collapsing.
ExpandableAnimationTransitionBuilder Signature for custom layer transitions.
ExpandedBoundsContext Layout information passed to custom bounds resolvers.
ExpandableAnimationTheme / ExpandableAnimationThemeData App-wide defaults for every option.
ExpandableAnimationDismissDirection down, up, left, right for dismissDirections.
ExpandableAnimationSlot A shared element that flies on its own path during the transition.
ExpandableAnimationZoomable Pinch, pan and double-tap zoom that cooperate with drag-to-dismiss.
SpringCurve A Curve that follows a spring, usable anywhere.

Full documentation: pub.dev API reference.

Platform support

The package is pure Dart and uses only Flutter framework APIs, with no platform channels other than optional haptic feedback.

Platform Status
Android Integration tests pass on a physical phone (Android 13) and the Android emulator (Android 17).
iOS Integration tests pass on a physical iPhone 12 (iOS 27) and the iOS Simulator.
Web Built in CI; the live demo was tested manually in Chrome with a mouse.
macOS Example app builds and its integration tests pass on macOS desktop.
Windows Expected to work; not yet validated.
Linux Expected to work; not yet validated.

Accessibility considerations

  • The collapsed widget is exposed as a button. Set semanticLabel to describe what opens.
  • It is focusable and activates with Enter or Space.
  • The expanded view is a modal route: focus moves into it and returns to the source afterwards, and screen readers get a dismiss action.
  • The background scrim is labeled with backgroundSemanticLabel (default 'Close'); pass a localized string.
  • With respectReducedMotion (default), transitions are instant when the platform requests reduced motion.
  • Always offer a visible close button: drag-to-dismiss is not discoverable for everyone.

Performance considerations

  • Collapsed and expanded content is laid out once at its natural size and only scaled while the surface animates, so heavy content is not re-laid out every frame.
  • The collapsed copy stops painting once the expansion completes.
  • backgroundBlur re-renders everything behind the view every frame. It is off by default; profile before enabling it, especially on the web and low-end devices. The blur keeps a constant radius and fades in with opacity, which is cheaper than animating the radius.
  • Measured frame times are below. Measure your own app with ./scripts/benchmark.sh -d <device> (profile mode).

Measured frame times

Profile mode, Flutter 3.47.9, the example app, 8 open/close cycles per scenario (example/benchmark/perf_test.dart), measured on 2026-12-01. Times are averages in milliseconds per frame; "over budget" counts frames slower than 16.7 ms. The first three scenarios include the example's own content (generated gradient artwork); the "plain content" scenarios use solid colors and text, so they show the cost of the package itself.

Device Scenario Build avg Raster avg Raster p90 Over budget (build / raster)
iPhone 12 Card to fullscreen with slot 1.16 2.45 4.13 0 / 5 of 455
iPhone 12 Spring card with blur (sigma 6) 0.79 3.36 7.72 0 / 19 of 555
iPhone 12 Drag to dismiss 1.51 2.00 2.77 6 / 0 of 1096
iPhone 12 Plain content (package only) 1.28 1.42 1.77 0 / 0 of 448
iPhone 12 Plain content with blur (sigma 6) 1.22 1.93 2.47 0 / 0 of 560
Android, Snapdragon 765G Card to fullscreen with slot 2.64 8.74 14.27 3 / 36 of 419
Android, Snapdragon 765G Spring card with blur (sigma 6) 2.33 14.13 23.97 4 / 190 of 482
Android, Snapdragon 765G Drag to dismiss 4.31 7.25 9.34 23 / 6 of 1053
Android, Snapdragon 765G Plain content (package only) 3.54 4.65 6.00 11 / 1 of 415
Android, Snapdragon 765G Plain content with blur (sigma 6) 3.23 5.99 7.57 14 / 3 of 519
MacBook Pro, M1 Pro Card to fullscreen with slot 0.36 7.88 11.64 0 / 19 of 710
MacBook Pro, M1 Pro Spring card with blur (sigma 6) 0.29 4.84 8.77 0 / 6 of 1004
MacBook Pro, M1 Pro Drag to dismiss 0.32 4.74 5.28 0 / 0 of 1925
MacBook Pro, M1 Pro Plain content (package only) 0.80 1.34 1.94 0 / 0 of 829
MacBook Pro, M1 Pro Plain content with blur (sigma 6) 0.80 1.67 2.33 0 / 0 of 1041

Background blur is the most expensive option on mid-range Android: avoid it, or keep the blur radius small, on low-end hardware. Since the blur fades in at a constant radius, the plain-content blur scenario on the Snapdragon 765G phone went from 12.51 to 7.57 ms raster p90 and from 23 to 3 frames over budget; the iPhone 12 was unchanged.

Hero OpenContainer (animations package) ExpandableAnimation
Setup Matching tags on two routes One widget with open/closed builders One widget with child and expanded builder
Animates Shared element between routes Container transform to a new route Container transform to fullscreen, dialog, sheet or custom bounds
Interactive drag-to-dismiss No No Yes, with scroll coordination
Spring physics No No Yes
Programmatic control Via navigation Via the openContainer callback ExpandableAnimationController
Dependencies Flutter SDK animations package Flutter SDK

Each approach has its place: Hero is ideal for a shared element between two full pages, and OpenContainer follows the Material container transform specification closely. Expandable Animation focuses on interactive, gesture-driven expansion with one wrapper.

  • Nested navigators: by default the view opens on the root navigator and covers bottom navigation bars. Set useRootNavigator: false to open it inside the nearest navigator, such as a tab's, so 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" in your manifest, 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); a PopScope inside it can still veto the pop.

Known limitations

  • The child and the expanded view are separate widget instances. Keep state that must survive the transition (such as playback) outside both.
  • Inherited themes are carried into the expanded view, but other inherited widgets below the navigator (for example, providers placed under MaterialApp) are not; place them above the app or re-provide them.
  • A plain InteractiveViewer inside the expanded view competes with drag-to-dismiss; use ExpandableAnimationZoomable instead.
  • A pointer cancelled by the system mid-drag is treated like a release.
  • The expanded view is not a Material. Material widgets that need one, such as ListTile or InkWell, must be inside a Material or Scaffold in expandedBuilder.

Documentation

Roadmap

Planned, not yet available:

  • Windows and Linux validation
  • More built-in transition builders (fade-through, scale)

Contributing

Contributions are welcome. Read CONTRIBUTING.md, run ./scripts/ci.sh before opening a pull request, and follow the code of conduct.

License

MIT — see LICENSE.

Libraries

expandable_animation
Widget-to-fullscreen and card expansion animations for Flutter, with container morphing, spring physics and interactive drag-to-dismiss.