在一个页面中调用了动画,
在页面关闭的时候dispose了动画,但是发现在页面关闭的时候,动画并没有关闭,
并且报 xx was disposed with an active Ticker 错误
-------------
后来发现原来是dispose调用的顺序问题
参考:https://github.com/Norbert515/pimp_my_button/issues/2
Calling super.dispose() ahead of _controller.dispose() caused this error in my project.
Swapping it so that _controller.dispose() was called first fixed it:
@override
void dispose() {
_controller.dispose();
super.dispose();
}
super.dispose要最后调用

本文探讨了在Flutter中处理动画控制器的正确dispose顺序,避免动画未正常关闭及xx was disposed with an active Ticker错误。通过调整_super.dispose()和_controller.dispose()的调用顺序,确保动画资源被正确释放。
12万+

被折叠的 条评论
为什么被折叠?



