Morphing is what makes a transition feel physical: one object visibly changes shape instead of being
replaced. ExpandableAnimation morphs bounds, corners and color; this guide shows how to shape that
motion with springs and how to control what happens to the content inside.
Spring-driven morphs
ExpandableAnimation(
physics: const ExpandableAnimationPhysics.spring(
stiffness: 220,
dampingRatio: 0.72, // overshoots a little, then settles
),
borderRadius: BorderRadius.circular(24),
expandedBuilder: (context) => const ArticlePage(),
child: const StoryCard(),
)
With a damping ratio below 1.0 the surface grows slightly past its final bounds before settling. The
collapse always uses a critically damped spring, so it never undershoots the source. Presets:
smooth, bouncy and snappy.
Controlling the content
By default the child fades out and the expanded view fades in during the first 40% of the morph. Replace
that with a transitionBuilder — for example, a fade-through with a gap between the two:
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,
),
],
);
},
expandedBuilder: (context) => const DetailsPage(),
child: const SummaryCard(),
)
Using the spring curve elsewhere
The spring shape is exported as a regular Flutter Curve:
final physics = ExpandableAnimationPhysics.bouncy;
AnimatedScale(
scale: selected ? 1.1 : 1.0,
duration: physics.settleDuration,
curve: physics.curve,
child: const Icon(Icons.favorite),
)
Try it
Switch to Spring in the playground, or open the App Store-style cards demo.