动画断言失败

时间:2019-07-17 15:54:02

标签: flutter dart

这个断言跟随我出于某种原因现在使用不同的代码,对其进行搜索,发现flutter团队暂时还没有解决它,我们有什么可以做的吗?

v`I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 pos 15: 'parent != null': is not true.
I/chatty  ( 5598): uid=10085(com.example.gam3ity_aa) 1.ui identical 21 
lines
I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 pos 15: 'parent != null': is not true.
I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 pos 15: 'parent != null': is not true.
I/chatty  ( 5598): uid=10085(com.example.gam3ity_aa) 1.ui identical 10 
lines
I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 pos 15: 'parent != null': is not true.
I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 pos 15: 'parent != null': is not true.
I/chatty  ( 5598): uid=10085(com.example.gam3ity_aa) 1.ui identical 8 
lines
I/flutter ( 5598): Another exception was thrown: 
'package:flutter/src/animation/animations.dart': Failed assertion: line 
376 
 pos 15: 'parent != null': is not true.

`

1 个答案:

答案 0 :(得分:1)

当我不小心用 (parent: null) 创建了一个 Tween 对象时发生了这种情况

  @override
  void initState() {
    _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
      parent: null, // <---------------- This line should be an AnimationController
      curve: widget.curve,
      reverseCurve: widget.reverseCurve ?? widget.curve,
    ));
    super.initState();
  }

应该是这样的:

  AnimationController _animationController;
  Animation _animation;

  @override
  void initState() {
    _animationController = AnimationController(
        duration: Duration(milliseconds: 500),
        reverseDuration: Duration(milliseconds: 1000),
        vsync: this,
        value: 1.0
    );
    _animation = Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
      parent: _animationController,
      curve: widget.curve,
      reverseCurve: widget.reverseCurve ?? widget.curve,
    ));
    super.initState();
  }