Flutter 组件通信时遇到的问题
在fluttet的使用中组件通信是必不可少的…吧?:最近用组件通信时遇到了这样一个问题:
在退出当前页面后再次进入通过
[ERROR:flutter/shell/common/shell.cc(184)] Dart Error: Unhandled exception:
E/flutter (32275): setState() called after dispose(): _BaseHistiryChartState#88545(lifecycle state: defunct, not mounted)
E/flutter (32275): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback. The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the “mounted” property of this object before calling setState() to ensure the object is still in the tree.
代码如下
@override
void initState() {
// TODO: implement initState
super.initState();
this.type=widget.type;
this.time=widget.time