美文网首页
Flutter | super.dispose() 的调用顺序

Flutter | super.dispose() 的调用顺序

作者: 无夜之星辰 | 来源:发表于2021-07-16 23:55 被阅读0次

你看源码或者三方时应该都会发现:super.dispose() 是写在 dispose 方法最后的:

// _TabBarViewState 的 dispose
@override
void dispose() {
  if (_controllerIsValid)
    _controller!.animation!.removeListener(_handleTabControllerAnimationTick);
    _controller = null;
    // We don't own the _controller Animation, so it's not disposed here.
    super.dispose();
}

这个和 iOS 不一样,为什么在 Flutter 里最后调 super

这里有详细的回答:

https://stackoverflow.com/questions/58400001/should-i-call-super-initstate-at-the-end-or-at-the-beginning

相关文章

网友评论

      本文标题:Flutter | super.dispose() 的调用顺序

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