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
// 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.