Flutter,2个动画控制器导致错误

Flutter, 2 animation controllers result in error

我需要2个动画控制器,因为一个会一直播放,另一个只会播放一次。

但是由于某些原因,在初始化第二个动画控制器时应用程序崩溃了。

代码如下:

class _GlassTypeState extends State<GlassType>
    with SingleTickerProviderStateMixin {

  AnimationController _animationController;
  Animation _pulsateTween;

  AnimationController _opacityController;
  Animation _opacityTween;

  @override
  void initState() {
    super.initState();

    //WORKS Perfectly
    _animationController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 1000),
    );
    _pulsateTween = ColorTween(begin: Colors.white24, end: Colors.white)
        .animate(_animationController);
    _animationController.repeat(reverse: true);     
    //----

    _opacityController = AnimationController(
      vsync: this,
      duration: Duration(milliseconds: 1000),
    ); //ERROR happens here, if I comment this out no errors.

    // _opacityTween = Tween<double>(begin: 0, end: 1).animate(_opacityController);
    // _opacityController.forward();
  }

Flutter 的错误通常是无用的,但无论如何:

'package:flutter/src/widgets/framework.dart': Failed assertion: line 4345 pos 14: 'owner._debugCurrentBuildTarget == this': is not true.

type 'RenderErrorBox' is not a subtype of type 'RenderSemanticsGestureHandler' in type cast

有关更多上下文,我有一个小部件 AnimatedBuilder() 小部件在 build 方法中呈现,此小部件使用 _pulsateTween 补间并且工作正常。

我知道这一点,因为我已经尝试渲染空 Container(),但在创建第二个 AnimationController 时它仍然崩溃。

PS:如果这对你有用,请通知我,我会在 github.

上提交错误报告

这可能对以后的其他用户有帮助:

SingleTickerProviderStateMixin 应仅在存在 单个 AnimationController.

时使用

如果有多个 AnimationController 个实例处于同一状态,则应使用 TickerProviderStateMixin