Learn/Advanced UI/Advanced Animations

Advanced Animations

Master implicit, explicit, Hero, and staggered animations

9 min~5 min read+50 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Motion System Design
  2. 2. This Lesson In Simple Words
  3. 3. Your level focus
  4. 4. One practical habit
  5. 5. Deep Understanding Guide
  6. 6. Why this lesson matters
  7. 7. Study flow for better retention
  8. 8. Quick Glossary
  9. 9. Architecture Lens

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

Advanced Animations

Animations bring your Flutter app to life and guide users through transitions. Flutter provides two main animation approaches: implicit animations that handle everything automatically when a value changes, and explicit animations that give you full control through AnimationController. Mastering both approaches along with Hero transitions and staggered sequences allows you to create polished, production-quality motion design.

dart
1// ── IMPLICIT ANIMATIONS ──
2// Automatic transitions when values change
3
4AnimatedContainer(
5 duration: const Duration(milliseconds: 500),
6 curve: Curves.easeInOut,
7 width: _expanded ? 300 : 100,
8 height: _expanded ? 200 : 100,
9 decoration: BoxDecoration(
10 color: _expanded ? Colors.blue : Colors.red,
11 borderRadius: BorderRadius.circular(_expanded ? 20 : 50),
12 ),
13 child: const Center(child: Text('Tap me')),
14)
15
16// Other implicit widgets:
17// AnimatedOpacity : fade in/out
18// AnimatedPadding : animate padding
19// AnimatedAlign : animate alignment
20// AnimatedScale : animate scale
21// AnimatedSlide : animate position offset
22// AnimatedSwitcher: cross-fade between widgets
23
24AnimatedSwitcher(
25 duration: const Duration(milliseconds: 300),
26 transitionBuilder: (child, animation) {
27 return ScaleTransition(scale: animation, child: child);
28 },
29 child: Text(
30 '$_counter',
31 key: ValueKey<int>(_counter), // key triggers animation
32 style: const TextStyle(fontSize: 48),
33 ),
34)
35
36// TweenAnimationBuilder: custom implicit animation
37TweenAnimationBuilder<double>(
38 tween: Tween(begin: 0, end: _targetAngle),
39 duration: const Duration(seconds: 1),
40 builder: (context, angle, child) {
41 return Transform.rotate(angle: angle, child: child);
42 },
43 child: const Icon(Icons.refresh, size: 60),
44)
dart
1// ── EXPLICIT ANIMATIONS ──
2// Full control with AnimationController
3
4class PulseAnimation extends StatefulWidget {
5 const PulseAnimation({super.key});
6
7 @override
8 State<PulseAnimation> createState() => _PulseAnimationState();
9}
10
11class _PulseAnimationState extends State<PulseAnimation>
12 with SingleTickerProviderStateMixin {
13 late final AnimationController _controller;
14 late final Animation<double> _scaleAnim;
15 late final Animation<double> _opacityAnim;
16
17 @override
18 void initState() {
19 super.initState();
20 _controller = AnimationController(
21 vsync: this,
22 duration: const Duration(milliseconds: 1500),
23 );
24
25 _scaleAnim = Tween<double>(begin: 0.8, end: 1.2).animate(
26 CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
27 );
28
29 _opacityAnim = Tween<double>(begin: 1.0, end: 0.5).animate(
30 CurvedAnimation(parent: _controller, curve: Curves.easeIn),
31 );
32
33 _controller.repeat(reverse: true);
34 }
35
36 @override
37 Widget build(BuildContext context) {
38 return AnimatedBuilder(
39 animation: _controller,
40 builder: (context, child) {
41 return Transform.scale(
42 scale: _scaleAnim.value,
43 child: Opacity(
44 opacity: _opacityAnim.value,
45 child: child,
46 ),
47 );
48 },
49 child: Container(
50 width: 100, height: 100,
51 decoration: const BoxDecoration(
52 shape: BoxShape.circle, color: Colors.blue,
53 ),
54 ),
55 );
56 }
57
58 @override
59 void dispose() {
60 _controller.dispose();
61 super.dispose();
62 }
63}
dart
1// ── HERO ANIMATIONS ──
2// Shared element transitions between screens
3
4// Source screen
5Hero(
6 tag: 'profile-$userId',
7 child: CircleAvatar(
8 radius: 30,
9 backgroundImage: NetworkImage(user.avatarUrl),
10 ),
11)
12
13// Destination screen
14Hero(
15 tag: 'profile-$userId',
16 child: CircleAvatar(
17 radius: 80,
18 backgroundImage: NetworkImage(user.avatarUrl),
19 ),
20)
21
22// ── STAGGERED ANIMATIONS ──
23// Multiple animations running in sequence with offsets
24
25class StaggeredList extends StatefulWidget { ... }
26class _StaggeredListState extends State<StaggeredList>
27 with SingleTickerProviderStateMixin {
28 late final AnimationController _controller;
29
30 @override
31 void initState() {
32 super.initState();
33 _controller = AnimationController(
34 vsync: this,
35 duration: const Duration(milliseconds: 1500),
36 )..forward();
37 }
38
39 Animation<double> _getSlideAnimation(int index) {
40 final start = index * 0.1; // stagger by 100ms each
41 final end = start + 0.4;
42 return Tween<double>(begin: 50, end: 0).animate(
43 CurvedAnimation(
44 parent: _controller,
45 curve: Interval(start.clamp(0, 1), end.clamp(0, 1), curve: Curves.easeOut),
46 ),
47 );
48 }
49
50 @override
51 Widget build(BuildContext context) {
52 return AnimatedBuilder(
53 animation: _controller,
54 builder: (context, _) {
55 return Column(
56 children: List.generate(5, (i) {
57 final slide = _getSlideAnimation(i);
58 return Transform.translate(
59 offset: Offset(slide.value, 0),
60 child: Opacity(
61 opacity: (1 - slide.value / 50).clamp(0, 1),
62 child: ListTile(title: Text('Item $i')),
63 ),
64 );
65 }),
66 );
67 },
68 );
69 }
70}

Choosing the Right Animation

💡 Choosing the Right Animation

Use implicit animations (AnimatedContainer, AnimatedOpacity) when you only need to animate between two values. Use explicit animations with AnimationController when you need looping, sequencing, or fine-grained control. Use Hero for shared element transitions between screens. Use staggered animations when multiple elements should animate in a cascading sequence.

Motion System Design

Treat motion as a system with reusable rules:

  • Define standard durations and easing curves by interaction type.
  • Reserve long and dramatic transitions for key moments only.
  • Use motion to reinforce hierarchy, focus, and state change.
  • Keep animation interruption behavior predictable during rapid user input.

Systematic motion design creates polish without visual chaos.

Animation Production Checklist

  • Animation controllers are disposed and lifecycle-safe.
  • Reduced-motion accessibility considerations are addressed where possible.
  • Hero transitions have unique, collision-free tags.
  • Staggered sequences remain smooth on representative devices.
  • State changes remain understandable even if animations are skipped or interrupted.

This Lesson In Simple Words

Master implicit, explicit, Hero, and staggered animations. Animation gives feedback and personality to UI when it supports user intent clearly.

Your level focus

Operate with production and interview-level clarity.

One practical habit

Animate only what helps understanding, and keep transition timing consistent.

Deep Understanding Guide

Why this lesson matters

Good motion guides attention; bad motion distracts and can hurt performance.

Study flow for better retention

  1. Tie each concept to scale, failure handling, and delivery strategy.
  2. Prefer simple implicit animations first, then move to explicit control for complex flows.
  3. If you can defend trade-offs under constraints, your understanding is strong.

Common Mistakes To Avoid

  • Adding animation everywhere without UX purpose.
  • Rebuilding large widget trees for tiny animated changes.
  • Using inconsistent durations that make flows feel random.
  • Ignoring accessibility needs for users sensitive to motion.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Create one implicit and one explicit animation for the same component.
  • Use Hero transition between two screens with meaningful shared element.
  • Profile animation frame times and remove one avoidable rebuild hotspot.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "What is the key difference between implicit and explicit animations?".

Quick Glossary

  • state: Data that can change and update what the user sees.
  • animation: Controlled change in UI properties over time.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Architecture Lens

Animation architecture should separate timing logic from reusable visual components.

As your app grows, keep UI, state, and data responsibilities separate so each part stays testable and easier to modify.

Lesson Completion Checklist

  • I can explain "Advanced Animations" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Adding animation everywhere without UX purpose.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

What is the key difference between implicit and explicit animations?

Implicit animations (AnimatedContainer, AnimatedOpacity) animate automatically when values change. Explicit animations require you to create and manage an AnimationController for full control.

What makes a Hero animation work between two screens?

Hero widgets on the source and destination screens must share the same tag value. Flutter automatically animates the transition between them during navigation.

What mixin provides the vsync for AnimationController?

SingleTickerProviderStateMixin provides a single TickerProvider for one AnimationController. Use TickerProviderStateMixin when you need multiple controllers.

What does the Interval class do in staggered animations?

Interval maps a sub-range of the 0.0 to 1.0 animation range, letting each element animate during a different time window to create staggered effects.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue