美文网首页
flutter动画报错Tickers used by Anima

flutter动画报错Tickers used by Anima

作者: 梁典典 | 来源:发表于2020-11-24 09:22 被阅读0次

    先看一下报错

    
    ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
    The following assertion was thrown while finalizing the widget tree:
    _GlobalMenuAnimationState#d5443(tickers: tracking 1 ticker) was disposed with an active Ticker.
    
    _GlobalMenuAnimationState created a Ticker via its TickerProviderStateMixin, but at the time dispose() was called on the mixin, that Ticker was still active. All Tickers must be disposed before calling super.dispose().
    
    Tickers used by AnimationControllers should be disposed by calling dispose() on the AnimationController itself. Otherwise, the ticker will leak.
    
    The offending ticker was: _WidgetTicker(created by _GlobalMenuAnimationState#d5443(lifecycle state: created, tickers: tracking 0 tickers))
    The stack trace when the _WidgetTicker was actually created was:
    #0      new Ticker.<anonymous closure> (package:flutter/src/scheduler/ticker.dart:67:40)
    
    
    When the exception was thrown, this was the stack: 
    #0      TickerProviderStateMixin.dispose.<anonymous closure> (package:flutter/src/widgets/ticker_provider.dart:221:13)
    #1      TickerProviderStateMixin.dispose (package:flutter/src/widgets/ticker_provider.dart:239:6)
    ...
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    
    ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
    _GlobalMenuAnimationState#78c35(tickers: tracking 1 ticker) was disposed with an active Ticker.
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    
    

    解决方法

    销毁AnimationController的时候要放在super.dispose()语句前面!!
    例子

     @override
     void dispose() {
       _animatedContainer.dispose();
       super.dispose();
     }
    

    下面这样就会报错

      @override
      void dispose() {
        super.dispose();
        _animatedContainer.dispose();
      }
    

    (灬ꈍ ꈍ灬) 还搞不懂这是啥原因,有无大佬解释一下

    相关文章

      网友评论

          本文标题:flutter动画报错Tickers used by Anima

          本文链接:https://www.haomeiwen.com/subject/bktiiktx.html