Flutter 颤振,2个动画控制器导致错误
我需要有2个动画控制器,因为一个将永远播放,另一个将只播放一次 但由于某些原因,在初始化第二个动画控制器应用程序时崩溃 代码如下:Flutter 颤振,2个动画控制器导致错误,flutter,animation,flutter-layout,flutter-animation,Flutter,Animation,Flutter Layout,Flutter Animation,我需要有2个动画控制器,因为一个将永远播放,另一个将只播放一次 但由于某些原因,在初始化第二个动画控制器应用程序时崩溃 代码如下: class _GlassTypeState extends State<GlassType> with SingleTickerProviderStateMixin { AnimationController _animationController; Animation _pulsateTween; AnimationContr
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();
}
对于更多上下文,我有一个小部件AnimatedBuilder()
在build
方法中呈现,这个小部件在之间使用\u脉动,工作正常
我知道这一点,因为我尝试过渲染空的Container()
,但在创建第二个AnimationController
时它仍然崩溃
PS:如果这对您很好,请通知我,我将在github上做一个bug报告。这可能会在将来帮助其他用户:
SingleTickerProviderStateMixin
仅当存在单个动画控制器时才应使用
如果有多个AnimationController
实例处于同一状态,则应使用TickerProviderStateMixin
。您有多个AnimationController,并且正在使用SingleTickerProviderStateMixin
。SingleTickerProviderStateMixin
只能与一个动画控制器一起使用。将其替换为TickerProviderStateMixin
,它应该可以工作。@danypata谢谢,你能写下这个作为答案吗?
'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