是否有通用类型的 AnimationController?如果不是,为什么?

Are there generic types of AnimationController? If not, why?

这里是 Flutter 新手。我将 Tween 与 AnimationController 一起使用。我正在尝试将 animateTo() 方法与 Offset 类型的目标一起使用。这可能吗?

文档说:

animateTo(double target, { Duration duration, Curve curve: Curves.linear }) → TickerFuture

Drives the animation from its current value to target

动画控制器:

_controller = AnimationController(
  duration: const Duration(milliseconds: 500),
  vsync: this,
);

AnimateTo():

_controller.animateTo(Offset(0,0))

上面一行不正确:

The argument type 'Offset' can't be assigned to the parameter type 'double'.dart(argument_type_not_assignable)

AnimationController 有泛型吗?如果不是,为什么?我知道我可以使用 Tween<Offset>(begin:.., end:..).animate(_controller)。但看起来 animateTo() 和类似的 AnimationController 方法只适用于双精度类型的目标。这看起来令人困惑。

你需要的是这个,

var _controller = AnimationController(vsync: this, duration: Duration(seconds: 2));

var _animation = Tween(begin: Offset(0,0), end: Offset(5,5));

_controller.animateTo(0.5);

Tween class 是一个 Animatable,它为您的动画生成插值。 animateTo 方法得到一个介于 0 和 1 之间的值(尽管您可以在 AnimationController 的构造函数中自己定义这些边界,默认值是 0 和 1)。例如,如果您将 0.5 赋给 animateTo 方法,您将在偏移值之间的中间设置动画。

没有。 AnimationController 只处理 double.

AnimationController使用的doubledouble的含义不同=32=]吐温.

AnimationController只是动画的进度,而Tween可能经过很多层变换后输出一个值

因此,不仅很难将转换后的值转换回它所代表的进度,而且还存在局限性:

曲线。如果 AnimationController 应该处理任何可补间对象,那么它也会隐式支持曲线。

问题是,我们可以有这样的曲线:

但这提出了一个问题。正如我们在前面的 gif 中看到的那样,经过曲线转换后,我们可以多次发出相同的值。

在那种情况下,如果控制器可以多次发射 X,animateTo(X) 需要的行为是什么?

这没有意义。因此,AnimationController 仅使用线性浮动值。如果我们想要更复杂的行为,我们必须使用不同的对象。