Mastering Flutter Animations with AnimationController
A hands-on guide to Flutter animations — from basic fades to complex staggered sequences and Hero transitions.
Abhinav Birajdar
Creator
Why Animations Matter
Animations aren't decoration — they're communication. A well-timed transition tells the user what just happened and what to expect next. Flutter's animation system is one of the most powerful in mobile development; let's make the most of it.
Core Concepts
Before diving into code, understand three fundamental building blocks:
AnimationController — The engine. Drives an animation between 0.0 and 1.0 over a duration.
Tween — The translator. Maps the 0.0–1.0 value to a useful range (colors, sizes, positions).
CurvedAnimation — The personality. Applies an easing curve to the animation progress.
dart1class _MyAnimatedWidgetState extends State<MyAnimatedWidget> 2 with SingleTickerProviderStateMixin { 3 late AnimationController _controller; 4 late Animation<double> _opacity; 5 late Animation<Offset> _slide; 6 7 8 void initState() { 9 super.initState(); 10 11 _controller = AnimationController( 12 duration: const Duration(milliseconds: 400), 13 vsync: this, 14 ); 15 16 _opacity = Tween<double>(begin: 0.0, end: 1.0).animate( 17 CurvedAnimation(parent: _controller, curve: Curves.easeOut), 18 ); 19 20 _slide = Tween<Offset>( 21 begin: const Offset(0, 0.1), 22 end: Offset.zero, 23 ).animate( 24 CurvedAnimation(parent: _controller, curve: Curves.easeOut), 25 ); 26 } 27 28 29 void dispose() { 30 _controller.dispose(); // Always dispose! 31 super.dispose(); 32 } 33}
Fade Transition
The simplest and most useful animation. Use it for any appearing/disappearing UI.
dart1FadeTransition( 2 opacity: _opacity, 3 child: SlideTransition( 4 position: _slide, 5 child: const MyCard(), 6 ), 7)
Hero Animations
Hero animations create shared-element transitions between screens. Flutter handles the interpolation automatically — you just tag the widgets.
dart1// Screen A: the source 2GestureDetector( 3 onTap: () => Navigator.push(context, MaterialPageRoute( 4 builder: (_) => const ProductDetailScreen(), 5 )), 6 child: Hero( 7 tag: 'product-image-${product.id}', // Must be unique and match destination 8 child: Image.network(product.imageUrl), 9 ), 10) 11 12// Screen B: the destination 13Hero( 14 tag: 'product-image-${product.id}', 15 child: Image.network(product.imageUrl), 16)
Hero animation rules:
- The
tagmust be identical on both screens - Only one Hero with a given tag can exist on screen at a time
- Works automatically with
Navigator.push— no extra setup needed
Staggered Animations
Staggered animations offset multiple animations in time, creating a cascading effect that feels polished and intentional.
dart1class StaggeredListAnimation extends StatefulWidget { 2 final List<Widget> children; 3 const StaggeredListAnimation({required this.children, super.key}); 4 5 6 State<StaggeredListAnimation> createState() => _StaggeredListAnimationState(); 7} 8 9class _StaggeredListAnimationState extends State<StaggeredListAnimation> 10 with SingleTickerProviderStateMixin { 11 late AnimationController _controller; 12 13 14 void initState() { 15 super.initState(); 16 _controller = AnimationController( 17 duration: Duration(milliseconds: 600 + (widget.children.length * 80)), 18 vsync: this, 19 )..forward(); 20 } 21 22 23 Widget build(BuildContext context) { 24 return Column( 25 children: widget.children.asMap().entries.map((entry) { 26 final index = entry.key; 27 final child = entry.value; 28 final start = index * 0.1; 29 final end = (start + 0.6).clamp(0.0, 1.0); 30 31 final animation = Tween<double>(begin: 0.0, end: 1.0).animate( 32 CurvedAnimation( 33 parent: _controller, 34 curve: Interval(start, end, curve: Curves.easeOut), 35 ), 36 ); 37 38 return FadeTransition( 39 opacity: animation, 40 child: SlideTransition( 41 position: Tween<Offset>( 42 begin: const Offset(0, 0.15), 43 end: Offset.zero, 44 ).animate(animation), 45 child: child, 46 ), 47 ); 48 }).toList(), 49 ); 50 } 51}
Implicit Animations: AnimatedContainer
For simple property changes, Flutter's implicit animations require almost no code.
dart1bool _isExpanded = false; 2 3AnimatedContainer( 4 duration: const Duration(milliseconds: 300), 5 curve: Curves.easeInOut, 6 height: _isExpanded ? 200 : 80, 7 padding: EdgeInsets.all(_isExpanded ? 24 : 12), 8 decoration: BoxDecoration( 9 color: _isExpanded 10 ? Theme.of(context).colorScheme.primaryContainer 11 : Theme.of(context).colorScheme.surface, 12 borderRadius: BorderRadius.circular(_isExpanded ? 16 : 8), 13 ), 14 child: const MyContent(), 15)
Other useful implicit animation widgets:
AnimatedOpacityAnimatedPaddingAnimatedPositionedAnimatedAlignAnimatedDefaultTextStyleAnimatedCrossFade
Curves Reference
Flutter's built-in curves cover almost every use case:
| Curve | Best For |
|---|---|
Curves.easeOut | Most UI transitions (feels natural) |
Curves.easeInOut | Expanding/collapsing elements |
Curves.elasticOut | Playful "bounce in" effects |
Curves.bounceOut | Game-like feedback |
Curves.linear | Loading spinners, progress bars |
Curves.fastOutSlowIn | Material Design motion |
Curves.decelerate | Items flying into position |
Performance Tips
- Use
RepaintBoundaryto isolate animated widgets from static content - Prefer
TransformandOpacityover properties that trigger layout (width, height, padding) - Use
flutter analyze --performanceand DevTools' Frame chart to spot jank - Animations that trigger layout recalculations (e.g., changing padding in AnimatedContainer) are more expensive than transform-only animations
- Target 60fps minimum; 120fps on capable devices
Conclusion
Flutter's animation APIs reward investment. Start with implicit animations (AnimatedContainer, AnimatedOpacity) for most cases — they're fast to write and look great. Reach for AnimationController when you need precise timing, staggering, or composing multiple animations together. And use Hero for free, beautiful shared-element transitions between screens.