Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Animation failed assertion flutter

Tags:

flutter

dart

This assertion follows me around using different codes for some reason now, searching about it and found that the flutter team hasn't solved it yet for a while now, is there anything we can do?

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.

`

like image 218
ahmed osman Avatar asked Jul 17 '19 15:07

ahmed osman


Video Answer


1 Answers

This was happening for me when accidentally creating a Tween object with (parent: null)

  @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();
  }

It should have been like this:

  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();
  }
like image 52
BananaNeil Avatar answered Oct 25 '22 06:10

BananaNeil