动画失败断言 Flutter

7

这个断言一直困扰着我,无论使用哪种代码都会出现这个问题。经过搜索,发现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.

`


3
你的代码中是否创建了任何 AnimationController?如果是,能否展示一下? - Sander Dalby Larsen
1个回答

2
当我意外地使用(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();
  }

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接