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;
});
});
}