D
AnimationsMedium30 XP3 min read

What is the difference between AnimatedBuilder and AnimatedWidget?

TL;DR: AnimatedBuilder is a general-purpose widget that rebuilds its builder on every animation tick. AnimatedWidget is a base class for creating reusable animated widgets that subscribe to a Listenable internally.

Full Answer

Both serve the same purpose โ€” rebuilding part of the UI on every animation frame โ€” but differ in how you use them.

AnimatedBuilder

Use AnimatedBuilder inline when the animation is local to one build() method. Pass a child for the non-animating subtree to avoid rebuilding it.

AnimatedWidget

Subclass AnimatedWidget when you want a reusable, self-contained animated widget. Override build() and use widget.listenable.value (or cast to Animation<T>) directly.

๐ŸŽฏ

AnimatedWidget is cleaner for library-style widgets. AnimatedBuilder is simpler for one-off animations inside a build method.

Code Examples

dartAnimatedWidget โ€” reusable spinning widget
Output
// FlutterLogo spins continuously

Common Mistakes

  • โœ—Forgetting to call super(listenable: animation) in AnimatedWidget
  • โœ—Not using the child optimization in AnimatedBuilder โ€” causes expensive subtrees to rebuild every frame

Interview Tip

๐Ÿ’ก

AnimatedWidget is essentially a ListenableBuilder specialized for animations. Point out that many built-in Flutter widgets (FadeTransition, ScaleTransition) are subclasses of AnimatedWidget.

#animated-builder#animated-widget#listenable#rebuild