
A container transform morphs the whole card into the page. Often one element — a product photo, an
avatar, album artwork — should travel on its own path: from its exact spot in the card to its
exact spot in the page, without being scaled with the rest of the card. That is a shared element
transition, and ExpandableAnimationSlot adds it inside the morph.
Mark the element on both sides
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),
],
),
)
How it behaves
- While the view expands or collapses, both slots stay in their layouts but are hidden, and a copy flies between their live on-screen bounds every frame.
- The copy cross-fades from the collapsed content to the expanded content, so a thumbnail can hand over to a higher-resolution image.
- It is fitted with
fit(defaultBoxFit.cover) and clipped to a radius that interpolates between the two slots'borderRadius. - Slots fly during the expansion, the collapse and the collapse after a drag-to-dismiss. While the user drags, they stay in place.
- Tags must be unique within the card and within the page. A tag on only one side does not fly.
Compared with Hero
Flutter's Hero animates a shared element between two full routes. A slot animates a shared
element inside an expanding container — the card itself still morphs, can be dismissed with a drag
and can open as a dialog or sheet. See the comparison
with Hero and OpenContainer.
Try it
Open the product card demo and watch the product image. Related: card to fullscreen animation.