先看一下报错
════════ 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();
}
(灬ꈍ ꈍ灬) 还搞不懂这是啥原因,有无大佬解释一下
网友评论