D
AnimationsEasy20 XP2 min read

When should you use TweenAnimationBuilder?

TL;DR: TweenAnimationBuilder is an implicit animation widget that animates to a new target value whenever it changes. It's great for one-off transitions where you don't need to store a controller.

Full Answer

TweenAnimationBuilder fills the gap between pre-built implicit widgets (AnimatedContainer) and full explicit animations.

You provide a Tween, a duration, and a builder. When the tween's end value changes, it automatically animates from the current value to the new target.

๐ŸŽฏ

Unlike AnimatedContainer which only animates a fixed set of properties, TweenAnimationBuilder can animate any type that has a lerp โ€” even custom objects.

Code Examples

dartTweenAnimationBuilder for custom double animation
Output
// Progress bar animates to new _progress value every time it changes

Common Mistakes

  • โœ—Changing the tween's begin value mid-animation โ€” TweenAnimationBuilder uses current value as the new begin automatically
  • โœ—Using it for looping animations โ€” it's not designed for repeat(); use AnimationController

Interview Tip

๐Ÿ’ก

TweenAnimationBuilder is stateful internally โ€” it manages its own controller. This makes it perfect for driven data animations (progress bars, counters) without extra state management.

#tween-animation-builder#implicit#self-contained