What makes Hero animation work?
Hero widgets with the same tag automatically animate between routes.
Add smooth animations to your app
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
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
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.
1// AnimatedContainer - animates size, color, etc.2AnimatedContainer(3duration: Duration(milliseconds: 300),4width: isExpanded ? 200 : 100,5height: isExpanded ? 200 : 100,6color: isExpanded ? Colors.blue : Colors.red,7curve: Curves.easeInOut,8child: Center(child: Text('Tap me')),9)1011// AnimatedOpacity - fade in/out12AnimatedOpacity(13duration: Duration(milliseconds: 500),14opacity: isVisible ? 1.0 : 0.0,15child: Text('Fading text'),16)1718// AnimatedPositioned - animate position19AnimatedPositioned(20duration: Duration(milliseconds: 300),21left: isLeft ? 0 : 100,22top: 50,23child: Container(width: 50, height: 50, color: Colors.blue),24)
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.
1// Screen 1 - Image thumbnail2Hero(3tag: 'product-image-$productId', // Unique tag4child: Image.network(product.imageUrl),5)67// Screen 2 - Full image (same tag!)8Hero(9tag: 'product-image-$productId',10child: Image.network(product.imageUrl),11)1213// Flutter automatically animates between matching Hero widgets!
Use implicit animations for simple cases. The Hero tag must be unique and match exactly between screens.
Use animation to support understanding, not to decorate everything.
Meaningful motion improves usability and perceived quality.
Add smooth animations to your app. Animation gives feedback and personality to UI when it supports user intent clearly.
Connect each concept to real app features you can build.
Animate only what helps understanding, and keep transition timing consistent.
Good motion guides attention; bad motion distracts and can hurt performance.
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.
Hero widgets with the same tag automatically animate between routes.
AnimatedContainer animates all its visual properties when they change: width, height, color, padding, etc.
The curve property (e.g., Curves.easeInOut) controls the animation's acceleration and deceleration.
AnimatedOpacity smoothly fades a widget in or out by animating the opacity from 0.0 to 1.0.
Something seems incorrect, unclear, or missing? Let us know.
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