forEachTween method

  1. @protected
void forEachTween (TweenVisitor visitor)

Subclasses must implement this function by running through the following steps for each animatable facet in the class:

  1. Call the visitor callback with three arguments, the first argument being the current value of the Tween object that represents the tween (initially null), the second argument, of type T, being the value on the Widget that represents the current target value of the tween, and the third being a callback that takes a value T (which will be the second argument to the visitor callback), and that returns an Tween object for the tween, configured with the given value as the begin value.

  2. Take the value returned from the callback, and store it. This is the value to use as the current value the next time that the forEachTween method is called.

Subclasses that contain properties based on tweens created by forEachTween should override didUpdateTweens to update those properties. Dependent properties should not be updated within forEachTween.

Sample code implementing an implicitly animated widget's State. The widget animates between colors whenever widget.targetColor changes.
class MyWidgetState extends AnimatedWidgetBaseState<MyWidget> {
  ColorTween _colorTween;

  Widget build(BuildContext context) {
    return Text(
      'Hello World',
      // Computes the value of the text color at any given time.
      style: TextStyle(color: _colorTween.evaluate(animation)),

  void forEachTween(TweenVisitor<dynamic> visitor) {
    // Update the tween using the provided visitor function.
    _colorTween = visitor(
      // The latest tween value. Can be `null`.
      // The color value toward which we are animating.
      // A function that takes a color value and returns a tween
      // beginning at that value.
      (value) => ColorTween(begin: value),

    // We could have more tweens than one by using the visitor
    // multiple times.


void forEachTween(TweenVisitor<dynamic> visitor);