DEV Community

Cover image for Flutter Animations: From Implicit to Explicit, and When to Use Each
Yadnesh Teli
Yadnesh Teli

Posted on AI-assisted

Flutter Animations: From Implicit to Explicit, and When to Use Each

Series 6 — Part 1 of 1

Flutter Animations: From Implicit to Explicit, and When to Use Each

A standalone guide on mastering Flutter's animation primitives

Animations had been on my backlog for weeks. Everything I built was functional but static. My mentor suggested I dedicate time specifically to the Flutter animation system — not just using packages, but understanding how the underlying primitives work.

I spent two days reading the Flutter animation docs and implementing a series of examples that moved from the simplest implicit animations up to AnimationController with custom curves and sequences.

Implicit animations: the easy starting point

Flutter's implicit animation widgets handle the AnimationController lifecycle for you. AnimatedContainer is the classic example — change any property (color, size, padding) and Flutter will tween between the old and new values over a specified duration:

AnimatedContainer(
  duration: const Duration(milliseconds: 300),
  curve: Curves.easeInOut,
  width: _expanded ? 200 : 100,
  color: _expanded ? Colors.blue : Colors.grey,
)
Enter fullscreen mode Exit fullscreen mode

Other useful implicit widgets:

  • AnimatedOpacity (fade in/out)
  • AnimatedPadding
  • AnimatedDefaultTextStyle
  • AnimatedPositioned inside a Stack

These cover most UI transitions without any manual controller management.

Explicit animations with AnimationController

When you need full control — custom sequences, interruption handling, or value-driven animations — you move to explicit animations with AnimationController:

class _MyWidgetState extends State<MyWidget> with SingleTickerProviderStateMixin {
  late final AnimationController _controller;
  late final Animation<double> _opacity;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(milliseconds: 500),
      vsync: this,
    );
    _opacity = Tween<double>(begin: 0, end: 1).animate(
      CurvedAnimation(parent: _controller, curve: Curves.easeIn),
    );
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }
}
Enter fullscreen mode Exit fullscreen mode

The vsync: this mixin (SingleTickerProviderStateMixin) ties the animation to the widget's frame callback, preventing off-screen animations from consuming resources.

Fixing bugs in the implementation

  • Missed First Frame: I hit a bug where the animation was completing but the widget was not rebuilding. The cause: I was calling setState() inside the animation listener, but the listener was added after _controller.forward() — so the first frame was missed. The fix was to add the listener before calling forward().
  • Controller in ViewModel anti-pattern: I also saw a common mistake when integrating animations into an MVVM app: putting AnimationController inside a ViewModel. This does not work because AnimationController requires a TickerProvider (a vsync), which is a widget concern. AnimationController belongs in a State class, not a ViewModel.

What I learned

  • Start simple: Start with implicit animations (AnimatedContainer, AnimatedOpacity) — they cover most use cases.
  • Control with explicit: Use explicit AnimationController when you need sequencing, interruption, or programmatic control.
  • Lifecycle cleanup: Always dispose AnimationController in dispose() — skipping this leaks memory.
  • MVVM boundary: AnimationController belongs in State, not ViewModel — it requires a TickerProvider.
  • Listener order: Add animation listeners before calling forward() or reverse() to catch the first frame.

Top comments (0)