Using Package:animations to Add Material Motion Transitions
Aug 1, 2025



Summary
Summary
Summary
Summary
This tutorial demonstrates how to integrate Flutter’s animations package to add three Material motion transitions: SharedAxisTransition for axis-based navigation, FadeThroughTransition for gentle cross-fades, and OpenContainer for container transforms. Code examples cover setup, duration tuning, and best practices for wrapping transitions in Material widgets. Elevate your mobile app with polished, context-aware animations.
This tutorial demonstrates how to integrate Flutter’s animations package to add three Material motion transitions: SharedAxisTransition for axis-based navigation, FadeThroughTransition for gentle cross-fades, and OpenContainer for container transforms. Code examples cover setup, duration tuning, and best practices for wrapping transitions in Material widgets. Elevate your mobile app with polished, context-aware animations.
This tutorial demonstrates how to integrate Flutter’s animations package to add three Material motion transitions: SharedAxisTransition for axis-based navigation, FadeThroughTransition for gentle cross-fades, and OpenContainer for container transforms. Code examples cover setup, duration tuning, and best practices for wrapping transitions in Material widgets. Elevate your mobile app with polished, context-aware animations.
This tutorial demonstrates how to integrate Flutter’s animations package to add three Material motion transitions: SharedAxisTransition for axis-based navigation, FadeThroughTransition for gentle cross-fades, and OpenContainer for container transforms. Code examples cover setup, duration tuning, and best practices for wrapping transitions in Material widgets. Elevate your mobile app with polished, context-aware animations.
Key insights:
Key insights:
Key insights:
Key insights:
Setup: Install and import the animations package to access Material motion widgets.
SharedAxisTransition: Animate screen changes along X, Y, or Z axes to maintain context.
FadeThroughTransition: Combine fade and scale to transition between unrelated UI elements smoothly.
OpenContainerTransition: Leverage container transform to animate a widget expanding into its detail view.
Best Practice: Wrap transition widgets in Material-themed contexts to preserve elevation and theming.
Introduction
Material motion is a cornerstone of modern mobile app design, guiding user attention and reinforcing spatial relationships. Flutter’s animations
package offers a suite of ready-made transition widgets that implement Material motion patterns, saving you time and ensuring consistency. In this tutorial, you’ll learn how to integrate the animations
package into your Flutter project and apply three key transition types: SharedAxisTransition, FadeThroughTransition, and OpenContainer (container transform). Each section includes concise code snippets and best practices to help you enhance navigation and interactions with smooth, context-aware animations.
Setup and Installation
Before diving into transitions, add the package to your pubspec.yaml
:
dependencies:
flutter:
sdk: flutter
animations
Run flutter pub get
to fetch dependencies. Then import the package in your Dart file:
import 'package:animations/animations.dart';
Ensure your app uses a MaterialApp
or Theme
that supports Material 3 for optimal appearance. Wrapping transition widgets in Theme
or Builder
is a best practice to apply your color and motion specs.
SharedAxisTransition
The SharedAxisTransition animates a change in UI along a common axis: X (horizontal), Y (vertical), or Z (depth). It’s ideal for navigation between related content views.
Define a
PageTransitionSwitcher
around your page content.Specify
transitionBuilder
usingSharedAxisTransition
with the desired axis and animation curves.
Example:
PageTransitionSwitcher(
duration: Duration(milliseconds: 300),
reverse: _isBackwards,
transitionBuilder: (child, primary, secondary) =>
SharedAxisTransition(
child: child,
animation: primary,
secondaryAnimation: secondary,
transitionType: SharedAxisTransitionType.horizontal,
),
child: _currentPage,
)
Toggle _isBackwards
and swap _currentPage
to animate between screens. This approach keeps your navigation stack intact and provides clear visual context for directional shifts.
FadeThroughTransition
When two UI elements are less directly related, FadeThroughTransition combines opacity and scale to create a gentle cross-fade effect. It’s perfect for switching between distinct content categories without strong hierarchical ties.
Usage is similar to SharedAxis, but replace the transition widget:
PageTransitionSwitcher(
duration: Duration(milliseconds: 250),
transitionBuilder: (child, primary, secondary) =>
FadeThroughTransition(
animation: primary,
secondaryAnimation: secondary,
child: child,
),
child: _selectedWidget,
)
Adjust duration
and wrap child content in Material
when necessary to preserve elevation and shadows. FadeThroughTransition excels in bottom navigation or tab switches where contextual relationship is low.
OpenContainerTransition (Container Transform)
The OpenContainer widget animates a container expanding into a new UI surface. This container transform transition visually links a list item, card, or button with its detailed view.
Example:
OpenContainer(
transitionDuration: Duration(milliseconds: 500),
openBuilder: (context, _) => DetailPage(item: item),
closedBuilder: (context, open) => ListTile(
title: Text(item.title),
onTap: open,
),
)
Key parameters:
openBuilder
: Builds the destination screen.closedBuilder
: Builds the triggering widget; call theopen
callback.transitionDuration
andopenColor
/closedElevation
for fine-tuning.
OpenContainer ensures smooth scaling, elevation, and color transitions that reinforce the relationship between list and detail views. Always wrap content in Material to maintain ripple effects and theming.
Vibe Studio

Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Integrating the animations
package in Flutter empowers you to implement Material motion patterns with minimal overhead. SharedAxisTransition streamlines directional navigation, FadeThroughTransition provides gentle cross-fades between unrelated views, and OpenContainerTransition delivers seamless container transforms. By following these code patterns and best practices, you can create polished, context-aware transitions that elevate your app’s user experience.
Introduction
Material motion is a cornerstone of modern mobile app design, guiding user attention and reinforcing spatial relationships. Flutter’s animations
package offers a suite of ready-made transition widgets that implement Material motion patterns, saving you time and ensuring consistency. In this tutorial, you’ll learn how to integrate the animations
package into your Flutter project and apply three key transition types: SharedAxisTransition, FadeThroughTransition, and OpenContainer (container transform). Each section includes concise code snippets and best practices to help you enhance navigation and interactions with smooth, context-aware animations.
Setup and Installation
Before diving into transitions, add the package to your pubspec.yaml
:
dependencies:
flutter:
sdk: flutter
animations
Run flutter pub get
to fetch dependencies. Then import the package in your Dart file:
import 'package:animations/animations.dart';
Ensure your app uses a MaterialApp
or Theme
that supports Material 3 for optimal appearance. Wrapping transition widgets in Theme
or Builder
is a best practice to apply your color and motion specs.
SharedAxisTransition
The SharedAxisTransition animates a change in UI along a common axis: X (horizontal), Y (vertical), or Z (depth). It’s ideal for navigation between related content views.
Define a
PageTransitionSwitcher
around your page content.Specify
transitionBuilder
usingSharedAxisTransition
with the desired axis and animation curves.
Example:
PageTransitionSwitcher(
duration: Duration(milliseconds: 300),
reverse: _isBackwards,
transitionBuilder: (child, primary, secondary) =>
SharedAxisTransition(
child: child,
animation: primary,
secondaryAnimation: secondary,
transitionType: SharedAxisTransitionType.horizontal,
),
child: _currentPage,
)
Toggle _isBackwards
and swap _currentPage
to animate between screens. This approach keeps your navigation stack intact and provides clear visual context for directional shifts.
FadeThroughTransition
When two UI elements are less directly related, FadeThroughTransition combines opacity and scale to create a gentle cross-fade effect. It’s perfect for switching between distinct content categories without strong hierarchical ties.
Usage is similar to SharedAxis, but replace the transition widget:
PageTransitionSwitcher(
duration: Duration(milliseconds: 250),
transitionBuilder: (child, primary, secondary) =>
FadeThroughTransition(
animation: primary,
secondaryAnimation: secondary,
child: child,
),
child: _selectedWidget,
)
Adjust duration
and wrap child content in Material
when necessary to preserve elevation and shadows. FadeThroughTransition excels in bottom navigation or tab switches where contextual relationship is low.
OpenContainerTransition (Container Transform)
The OpenContainer widget animates a container expanding into a new UI surface. This container transform transition visually links a list item, card, or button with its detailed view.
Example:
OpenContainer(
transitionDuration: Duration(milliseconds: 500),
openBuilder: (context, _) => DetailPage(item: item),
closedBuilder: (context, open) => ListTile(
title: Text(item.title),
onTap: open,
),
)
Key parameters:
openBuilder
: Builds the destination screen.closedBuilder
: Builds the triggering widget; call theopen
callback.transitionDuration
andopenColor
/closedElevation
for fine-tuning.
OpenContainer ensures smooth scaling, elevation, and color transitions that reinforce the relationship between list and detail views. Always wrap content in Material to maintain ripple effects and theming.
Vibe Studio

Vibe Studio, powered by Steve’s advanced AI agents, is a revolutionary no-code, conversational platform that empowers users to quickly and efficiently create full-stack Flutter applications integrated seamlessly with Firebase backend services. Ideal for solo founders, startups, and agile engineering teams, Vibe Studio allows users to visually manage and deploy Flutter apps, greatly accelerating the development process. The intuitive conversational interface simplifies complex development tasks, making app creation accessible even for non-coders.
Conclusion
Integrating the animations
package in Flutter empowers you to implement Material motion patterns with minimal overhead. SharedAxisTransition streamlines directional navigation, FadeThroughTransition provides gentle cross-fades between unrelated views, and OpenContainerTransition delivers seamless container transforms. By following these code patterns and best practices, you can create polished, context-aware transitions that elevate your app’s user experience.
Build Flutter Apps Faster with Vibe Studio
Build Flutter Apps Faster with Vibe Studio
Build Flutter Apps Faster with Vibe Studio
Build Flutter Apps Faster with Vibe Studio
Vibe Studio is your AI-powered Flutter development companion. Skip boilerplate, build in real-time, and deploy without hassle. Start creating apps at lightning speed with zero setup.
Vibe Studio is your AI-powered Flutter development companion. Skip boilerplate, build in real-time, and deploy without hassle. Start creating apps at lightning speed with zero setup.
Vibe Studio is your AI-powered Flutter development companion. Skip boilerplate, build in real-time, and deploy without hassle. Start creating apps at lightning speed with zero setup.
Vibe Studio is your AI-powered Flutter development companion. Skip boilerplate, build in real-time, and deploy without hassle. Start creating apps at lightning speed with zero setup.











