Flutter flutter: Another exception was thrown: setState() called after dispose()报错

原因是组件已经被销毁了但你仍然调用该组件的setState()这个方法

解决办法:

setState方法之前调用mouted属性进行判断即可。

if (mounted) {
_sctrollController = widget.sctrollController;
_sctrollController.addListener(() {
setState(() {
var scrollProportion = _sctrollController.offset / (400 - _statusBarHeight - 44);
var tempOffsetY = 60 - 60 * scrollProportion;
if (tempOffsetY > 60) {
tempOffsetY = 60;
}else if (tempOffsetY < 0) {
tempOffsetY = 0;
}
_offsetY = tempOffsetY;
});
});
}
posted @ 2020-08-17 14:43  D-Ben  阅读(1032)  评论(0编辑  收藏  举报