Mobile Development10 min read
Flutter Animations for Beginners
Learn Flutter animations from scratch: AnimatedContainer, Hero transitions, TweenAnimationBuilder and AnimationController, with copy-ready Dart examples.
- #flutter
- #animations
- #animatedcontainer
- #hero
- #ui

Most apps feel alive because small things move: a button grows when you tap it, a card slides into place, an image glides from a list into a detail page. In Flutter, those moments are not decoration. Motion tells the user what just happened, where they are, and what will happen next, and Flutter makes it cheap to add because animation is built into the widget system rather than bolted on. This guide starts from zero: the two kinds of animation Flutter offers, a working example of each, and which widget to reach for in real apps. Every example is complete Dart code you can paste into a project and run.
What are the two kinds of animation in Flutter?
Flutter animations fall into two groups: implicit animations and explicit animations. An implicit animation is one where you describe the end state and Flutter figures out the motion in between. You change a value, such as a width or a color, and the widget animates itself to the new value over a duration you choose. An explicit animation is one where you control the animation directly with an AnimationController, deciding exactly when it starts, stops, repeats, or reverses, and which values it produces along the way. Implicit animations are the right default for most interface work: less code, self-managed state, and coverage of the common cases — a container growing, a widget fading in, a list item sliding into place. Explicit animations are for anything that needs precise control, such as a looping loading indicator, a custom progress ring, a staggered entrance, or an animation tied to a gesture. Learn implicit animations first, then add explicit animations when a design needs control that an implicit widget cannot give you.
How do implicit animations work in Flutter?
An implicit animation in Flutter is a widget that watches one of its own properties and animates to a new value whenever that property changes, over a duration and curve you supply. You do not write animation code at all: you change the value in setState, and the widget handles the frames between the old value and the new one. The simplest way to see this is AnimatedContainer, which animates its size, color, padding, margin, and border radius whenever any of them change. Here is a card that grows, rounds its corners, and changes color when tapped:
class GrowingCard extends StatefulWidget {
const GrowingCard({super.key});
@override
State<GrowingCard> createState() => _GrowingCardState();
}
class _GrowingCardState extends State<GrowingCard> {
bool _expanded = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => setState(() => _expanded = !_expanded),
child: AnimatedContainer(
duration: const Duration(milliseconds: 300),
curve: Curves.easeInOut,
width: _expanded ? 220 : 140,
height: _expanded ? 220 : 140,
decoration: BoxDecoration(
color: _expanded ? Colors.teal : Colors.blue,
borderRadius: BorderRadius.circular(_expanded ? 24 : 8),
),
child: const Center(
child: Text('Tap me', style: TextStyle(color: Colors.white)),
),
),
);
}
}
Three details make this work. First, the duration sets how long the transition takes: 300 milliseconds is a good default for a tap response, long enough to be visible and short enough to feel instant. Second, the curve controls the pacing: Curves.easeInOut starts slow, speeds up, and slows down again, which reads as natural to the eye. Third, the widget must be a StatefulWidget, because the animation is triggered by a state change. The same pattern works for AnimatedOpacity, which fades a widget in and out, AnimatedPadding, which moves a widget by changing its padding, and AnimatedAlign, which slides a widget between alignment positions.
How does Hero animation work between screens?
A Hero animation in Flutter is a shared-element transition: a widget on one screen flies to its position on the next screen while the navigation itself happens. The classic example is a product image that grows from a small thumbnail in a list into a large banner on a detail page. The user sees one image moving instead of two separate screens, which makes the navigation feel like a single continuous space rather than a jump.
You build it by wrapping the same widget on both screens in a Hero widget with the same tag:
// On the list screen:
Hero(
tag: 'product-image',
child: Image.network(product.imageUrl),
)
// On the detail screen, with the same tag:
Hero(
tag: 'product-image',
child: Image.network(product.imageUrl),
)
The tag links the two widgets: identical on both screens and unique within the route, or Flutter will not know which widgets to connect. Wrap the same kind of child on both sides, ideally the same image at a different size, so the flight looks clean. Hero animations only work inside a Navigator push or pop, which means they work with MaterialPageRoute and with go_router, because both use the Navigator underneath. Keep the flight short, around 300 milliseconds, and avoid putting a Hero inside a scrolling list where the source widget can scroll away mid-flight.
When do you need an AnimationController?
You need an AnimationController when an implicit widget cannot express what you want: an animation that loops, reverses, runs on a timer, or follows a custom sequence of values. An AnimationController is the object that drives an explicit animation: it produces a value from 0.0 to 1.0 over a duration, and you map that value onto whatever you want to animate with a Tween. It lives in a State object, needs a TickerProvider for its vsync, and must be disposed when the widget is removed. Here is a heart button that pulses once when tapped:
class PulseButton extends StatefulWidget {
const PulseButton({super.key});
@override
State<PulseButton> createState() => _PulseButtonState();
}
class _PulseButtonState extends State<PulseButton>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
late final Animation<double> _scale;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 600),
);
_scale = Tween<double>(begin: 1.0, end: 1.2).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeOut),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => _controller.forward(from: 0),
child: AnimatedBuilder(
animation: _scale,
builder: (context, child) {
return Transform.scale(scale: _scale.value, child: child);
},
child: const Icon(Icons.favorite, size: 48, color: Colors.red),
),
);
}
}
The controller is the clock: forward() runs it from 0.0 to 1.0, reverse() runs it back, repeat() loops it forever, and forward(from: 0) restarts it from the beginning. The Tween maps that 0.0 to 1.0 progress onto real values, here a scale from 1.0 to 1.2, and the CurvedAnimation bends the pacing so the pulse eases out instead of moving at a constant speed. AnimatedBuilder rebuilds only the small subtree inside its builder on every frame, and the Icon is passed as child so it is built once and reused, which keeps the animation cheap. The two rules you must never break with a controller are to mix in SingleTickerProviderStateMixin for the vsync and to call dispose() on the controller, or the ticker will keep running after the widget is gone and leak memory.
How do you animate a value with TweenAnimationBuilder?
TweenAnimationBuilder is the middle ground between implicit widgets and a full AnimationController: it animates any value you can describe with a Tween, without a controller, a ticker, or a dispose method. You give it a Tween, a duration, and a builder that receives the current value on every frame, and it handles the rest. It is the right tool when no implicit widget covers your property, such as fading a widget while also scaling it, or animating a custom number like a progress ring. Here is a fade-in that needs no state at all:
TweenAnimationBuilder<double>(
tween: Tween<double>(begin: 0, end: 1),
duration: const Duration(milliseconds: 500),
builder: (context, value, child) {
return Opacity(opacity: value, child: child);
},
child: const Text('Hello, animations'),
)
To replay the animation, change the tween: when the end value changes, TweenAnimationBuilder animates from its current value to the new one. That makes it useful for live values such as a download progress bar. If the animation needs to start on its own, repeat, or reverse, reach for an AnimationController instead.
Which animation widget should you use?
Choosing the right widget is mostly a question of what is changing and how much control you need. This table covers the common cases:
| Situation | Widget to use |
|---|---|
| Size, color, padding, or radius changes on tap | AnimatedContainer |
| Widget fades in or out | AnimatedOpacity |
| Widget slides between two positions | AnimatedAlign or AnimatedPositioned |
| Same image moves between two screens | Hero |
| A value changes and no implicit widget fits | TweenAnimationBuilder |
| Looping, repeating, or gesture-driven motion | AnimationController with AnimatedBuilder |
| One widget swaps for another with a transition | AnimatedSwitcher |
| Start with the top of the table and move down only when the widget above cannot do the job. Most real apps need only the first four rows for their interface animations, plus a controller for the occasional loading indicator or custom effect. AnimatedSwitcher deserves a special mention: it cross-fades between two children whenever the child changes, but only if each child has a distinct Key, so give the children ValueKey values or the switcher cannot tell them apart. |
What are the most common animation mistakes?
The most common animation mistakes in Flutter are easy to make and easy to fix. First, rebuilding too much: if your animation rebuilds the whole screen on every frame, the frame budget disappears and the animation stutters. Use AnimatedBuilder and pass static widgets as its child so only the animated subtree rebuilds. Second, forgetting to dispose an AnimationController, which leaves a ticker running after the widget is gone. Third, animating layout properties on every frame: changing width and height forces the layout system to remeasure on each frame, so prefer Transform and Opacity, which the compositor can handle without a new layout pass, for anything that runs continuously. Fourth, durations that are too long: an entrance longer than about 500 milliseconds feels sluggish, and a tap response longer than 300 milliseconds feels unresponsive. Fifth, animating everything at once: when five widgets enter together, stagger them with short delays so the eye can follow the sequence. Sixth, using setState with a Timer to drive motion by hand, which produces uneven frames and wastes work that AnimationController already does correctly. Fix these six and your animations will look deliberate instead of accidental.
How do you make animations feel good?
Good animation in Flutter follows three simple rules: keep it short, keep it purposeful, and keep it consistent. Keep durations between 200 and 400 milliseconds for feedback like taps and toggles, and between 400 and 500 milliseconds for entrances and screen transitions. Use Curves.easeInOut for most interface motion, Curves.easeOut for things entering the screen, and Curves.easeIn for things leaving it. Give every similar interaction the same duration and curve across the app, so the motion becomes part of the product's character instead of a surprise on every screen. Motion should also respect the user: check MediaQuery.disableAnimations before running decorative animation, and skip non-essential motion when the user has reduced motion on. For a deeper example of animation in a real app, see Build a Breathing Pacer Animation in Flutter, which builds a full breathing exercise around an AnimationController. For the screens your animations live on, the layout rules in Flutter Responsive Design for Every Screen keep animated widgets looking right on every device, and Flutter Dark Mode: ThemeMode Done Right covers animated theme transitions between light and dark. Animation rewards practice more than theory, so pick one screen in your current project and animate a single interaction: a button that grows on tap, a card that fades in, a Hero image between two screens. Try 200, 300, and 400 milliseconds, keep the version that feels right, and repeat the pattern across the app. Small, consistent motion is what makes an app feel polished. Get in touch and let's talk about your project.
Frequently asked questions
- What is the difference between implicit and explicit animations in Flutter?
- Implicit animations describe the end state and let Flutter handle the motion, while explicit animations use an AnimationController for direct control over timing, repetition, and reversal. Use implicit animations for most interface work and explicit animations for looping, custom, or gesture-driven motion.
- How does AnimatedContainer work in Flutter?
- AnimatedContainer watches its own properties and animates to new values whenever they change, over a duration and curve you supply. Change a value such as width or color inside setState and the widget animates itself to the new value.
- How does a Hero animation work in Flutter?
- Wrap the same widget on two screens in a Hero widget with an identical tag. During navigation, Flutter flies the widget from its position on the first screen to its position on the second, creating a shared-element transition.
- When should you use TweenAnimationBuilder instead of AnimationController?
- Use TweenAnimationBuilder when no implicit widget covers the property you want to animate and you do not need looping, reversing, or gesture control. If the animation must start on its own, repeat, or reverse, use an AnimationController instead.


