Skip to main content

expandable_animation 0.1.0 copy "expandable_animation: ^0.1.0" to clipboard
expandable_animation: ^0.1.0 copied to clipboard

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

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
  • 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
  ),
  // ...
)

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 never affected. A PopScope with canPop: false inside the expanded view vetoes drag, background-tap, Escape and back-button dismissals.

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.
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 Expected to work; covered by headless widget tests. Not yet validated on a physical device.
iOS Expected to work; covered by headless widget tests. Not yet validated on a physical device.
Web Built in CI; demo verified in Chrome with mouse input.
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.
  • No frame-rate measurements are published yet. Profile in --profile mode on your target devices.
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.

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.
  • Zoomable content (InteractiveViewer) competes with drag-to-dismiss. Built-in zoom coordination is planned.
  • A pointer cancelled by the system mid-drag is treated like a release.

Documentation #

Roadmap #

Planned, not yet available:

  • Zoom and pan coordination for image viewers
  • Horizontal and multi-directional dismissal
  • Hover and focus effects for desktop
  • App-wide defaults through a theme extension
  • Shared element slots that morph individually

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.

0
likes
0
points
168
downloads

Publisher

verified publisherboffincoders.com

Weekly Downloads

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

Homepage
Repository (GitHub)
View/report issues

Topics

#animation #transition #expandable #fullscreen #gesture

License

unknown (license)

Dependencies

flutter

More

Packages that depend on expandable_animation