Flutter has two well-known ways to connect a small element to a larger view: the built-in Hero widget and OpenContainer from the official animations package. Both are good tools. This page explains where ExpandableAnimation differs, so you can pick the right one.

Side by side

HeroOpenContainerExpandableAnimation
ModelShared element flies between two routesContainer transforms into a new routeContainer transforms into an expanded view (a modal route)
SetupMatching tags in both pagesOne widget, closed and open buildersOne widget, child and expanded builder
TargetA full pageA full pageFullscreen, dialog, sheet or custom bounds
Drag-to-dismissNot built inNot built inBuilt in, with scroll coordination
Spring physicsNoNoOptional
ControllerNavigationopenContainer callbackExpandableAnimationController
DependencyFlutter SDKanimations packageexpandable_animation package

When Hero is the better choice

Use Hero when one element — an avatar, a product photo — should travel between two full pages that are otherwise independent, and the destination is a normal navigation push.

When OpenContainer is the better choice

Use OpenContainer when you want the Material container transform pattern exactly as the Material motion guidelines describe it, and a tap-to-open, back-to-close flow is enough.

When ExpandableAnimation fits

  • You want users to dismiss the view by dragging it, including from scrollable content.
  • You want to expand into a dialog or a partial sheet, not only a page.
  • You want spring motion, interruptible transitions and a controller with phase and progress.

Migrating from OpenContainer

// Before
OpenContainer(
  closedShape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
  closedBuilder: (context, open) => ProductCard(product: product),
  openBuilder: (context, close) => ProductDetails(product: product),
)

// After
ExpandableAnimation(
  borderRadius: BorderRadius.circular(16),
  expandedBuilder: (context) => ProductDetails(product: product),
  child: ProductCard(product: product),
)

Where your open page called close(), call ExpandableAnimation.of(context).collapse() or Navigator.pop(context).

Try it

Compare the feel in the live demo, or start with the card to fullscreen guide.