Implicit vs. Explicit Animation Architecture
Master Flutter animations from automatic transitions to manual frame choreography: compare Implicit widgets, TweenAnimationBuilder, AnimationController, and AnimatedBuilder performance caching.
1. Animation Spectrum: Implicit vs. Explicit
Flutter divides animation architectures into two primary categories based on control requirements:
| Dimension | Implicit Animations | Explicit Animations |
|---|---|---|
| Complexity | Extremely Low (Drop-in replacement) | Medium to High |
| Controller Required? | ❌ No controller needed | ✅ AnimationController mandatory |
| StatefulWidget Required? | ❌ Works in StatelessWidget | ✅ Requires TickerProviderStateMixin |
| Capabilities | Animate forward to target value | Loop, reverse, repeat, stagger, scrub, pause |
| Primary Widgets | AnimatedContainer, AnimatedOpacity, AnimatedPadding | AnimatedBuilder, SlideTransition, ScaleTransition |
2. Implicit Animations in Action
Whenever a property changes on an implicit animation widget, Flutter smoothly interpolates between the previous value and the new value over the specified duration:
class ExpandableCard extends StatefulWidget {
const ExpandableCard({super.key});
@override
State<ExpandableCard> createState() => _ExpandableCardState();
}
class _ExpandableCardState extends State<ExpandableCard> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => setState(() => _isExpanded = !_isExpanded),
child: AnimatedContainer(
duration: const Duration(milliseconds: 350),
curve: Curves.easeInOutCubic,
width: _isExpanded ? 320.0 : 160.0,
height: _isExpanded ? 200.0 : 80.0,
decoration: BoxDecoration(
color: _isExpanded ? Colors.indigo : Colors.blueGrey,
borderRadius: BorderRadius.circular(_isExpanded ? 24.0 : 12.0),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(_isExpanded ? 0.3 : 0.1),
blurRadius: _isExpanded ? 16.0 : 4.0,
),
],
),
alignment: Alignment.center,
child: AnimatedOpacity(
duration: const Duration(milliseconds: 200),
opacity: _isExpanded ? 1.0 : 0.7,
child: Text(
_isExpanded ? "Expanded Details" : "Tap to Expand",
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
);
}
}3. Custom One-Off Implicit Transitions: TweenAnimationBuilder
When you need an implicit animation for a custom property without writing a full StatefulWidget or controller:
// Smoothly animate counting up a bank balance
TweenAnimationBuilder<double>(
tween: Tween<double>(begin: 0.0, end: 1250.75),
duration: const Duration(seconds: 2),
curve: Curves.easeOutExpo,
builder: (BuildContext context, double value, Widget? child) {
return Text(
"\$${value.toStringAsFixed(2)}",
style: Theme.of(context).textTheme.displaySmall,
);
},
)4. Explicit Animations: AnimationController & AnimatedBuilder
When building choreographies, loops, or complex transformations, explicit animations provide complete control.
class PulseSpinner extends StatefulWidget {
const PulseSpinner({super.key});
@override
State<PulseSpinner> createState() => _PulseSpinnerState();
}
class _PulseSpinnerState extends State<PulseSpinner>
with SingleTickerProviderStateMixin {
late final AnimationController _controller;
late final Animation<double> _scaleAnimation;
late final Animation<double> _rotationAnimation;
@override
void initState() {
super.initState();
// 1. Initialize AnimationController tied to device VSYNC
_controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 2),
)..repeat(reverse: true); // Loops forward and reverse continuously
// 2. Define non-linear curves and output ranges
_scaleAnimation = Tween<double>(begin: 0.8, end: 1.2).animate(
CurvedAnimation(parent: _controller, curve: Curves.easeInOut),
);
_rotationAnimation = Tween<double>(begin: 0.0, end: 2 * 3.14159).animate(
CurvedAnimation(parent: _controller, curve: Curves.linear),
);
}
@override
void dispose() {
_controller.dispose(); // Mandatory cleanup
super.dispose();
}
@override
Widget build(BuildContext context) {
// ⚡ PERFORMANCE CRITICAL: AnimatedBuilder passes the static child
// The FlutterLogo child is instantiated ONCE and cached across 60/120 FPS frame ticks!
return AnimatedBuilder(
animation: _controller,
child: const FlutterLogo(size: 80), // Cached node!
builder: (BuildContext context, Widget? cachedChild) {
return Transform.scale(
scale: _scaleAnimation.value,
child: Transform.rotate(
angle: _rotationAnimation.value,
child: cachedChild, // Reused without calling child's build()!
),
);
},
);
}
}❓ Knowledge Check
Why is the child parameter in AnimatedBuilder critical for rendering performance during high-speed animations?
What is the role of SingleTickerProviderStateMixin when creating an AnimationController?
JSON Serialization & Data Models
Master serialization in Flutter without reflection: manual fromJson/toJson contracts, automated json_serializable code-gen, and immutable value objects with Freezed.
Physics Simulations, Hero Transitions & CustomPainter
Explore advanced motion graphics in Flutter: realistic spring physics simulations, shared element Hero transitions across routes, and low-level 2D graphics rendering with CustomPainter.