Learn/Styling & Polish/Animations Basics

Animations Basics

Add smooth animations to your app

6 min~5 min read+35 FX

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

Table of Contents

  1. 1. Hero Animations
  2. 2. Motion Design Rules
  3. 3. This Lesson In Simple Words
  4. 4. Your level focus
  5. 5. One practical habit
  6. 6. Deep Understanding Guide
  7. 7. Why this lesson matters
  8. 8. Study flow for better retention
  9. 9. Quick Glossary
  10. 10. 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

Implicit Animations

Flutter provides a family of animated widgets that handle animation logic for you automatically. You simply change a property value (like width, color, or opacity) and the widget smoothly transitions from the old value to the new one over a given duration. These are called implicit animations because you do not need to manage animation controllers, tickers, or any manual animation code. They are the easiest way to add polish and life to your app.

dart
1// AnimatedContainer - animates size, color, etc.
2AnimatedContainer(
3 duration: Duration(milliseconds: 300),
4 width: isExpanded ? 200 : 100,
5 height: isExpanded ? 200 : 100,
6 color: isExpanded ? Colors.blue : Colors.red,
7 curve: Curves.easeInOut,
8 child: Center(child: Text('Tap me')),
9)
10
11// AnimatedOpacity - fade in/out
12AnimatedOpacity(
13 duration: Duration(milliseconds: 500),
14 opacity: isVisible ? 1.0 : 0.0,
15 child: Text('Fading text'),
16)
17
18// AnimatedPositioned - animate position
19AnimatedPositioned(
20 duration: Duration(milliseconds: 300),
21 left: isLeft ? 0 : 100,
22 top: 50,
23 child: Container(width: 50, height: 50, color: Colors.blue),
24)

Hero Animations

Hero animations create a smooth visual transition of a shared element between two screens. For example, a small product image on a list screen can fly and expand into the full image on the detail screen. To set this up, wrap the same widget on both screens with a Hero widget and give them the same unique tag string. Flutter handles the rest automatically during navigation.

dart
1// Screen 1 - Image thumbnail
2Hero(
3 tag: 'product-image-$productId', // Unique tag
4 child: Image.network(product.imageUrl),
5)
6
7// Screen 2 - Full image (same tag!)
8Hero(
9 tag: 'product-image-$productId',
10 child: Image.network(product.imageUrl),
11)
12
13// Flutter automatically animates between matching Hero widgets!

Animation Tips

💡 Animation Tips

Use implicit animations for simple cases. The Hero tag must be unique and match exactly between screens.

Motion Design Rules

Use animation to support understanding, not to decorate everything.

  • animate state changes that matter to users
  • keep durations consistent across similar actions
  • avoid heavy motion for frequent interactions

Meaningful motion improves usability and perceived quality.

Animation Quality Checklist

  • Animation has clear UX purpose.
  • Duration and curve choices feel consistent.
  • Frame performance remains smooth on mid-range devices.
  • Motion does not block critical interaction flow.

This Lesson In Simple Words

Add smooth animations to your app. Animation gives feedback and personality to UI when it supports user intent clearly.

Your level focus

Connect each concept to real app features you can build.

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. Map the lesson to one screen, one user action, and one expected output.
  2. Prefer simple implicit animations first, then move to explicit control for complex flows.
  3. If you can choose between two approaches and explain why, you are improving.

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 makes Hero animation work?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.
  • 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 "Animations Basics" 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 makes Hero animation work?

Hero widgets with the same tag automatically animate between routes.

What does AnimatedContainer automatically animate?

AnimatedContainer animates all its visual properties when they change: width, height, color, padding, etc.

What property controls animation speed/style?

The curve property (e.g., Curves.easeInOut) controls the animation's acceleration and deceleration.

What does AnimatedOpacity animate?

AnimatedOpacity smoothly fades a widget in or out by animating the opacity from 0.0 to 1.0.

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