marcojakob/dart-event-bus

Getting an error that widget is not mounted

Closed this issue · 3 comments

setState() called after dispose(): MapState#dce2f(lifecycle state: defunct, not mounted)
E/flutter (14865): 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.
E/flutter (14865): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

Are you sure you wanted to post this as an issue in the event-bus package? I don't know how it is related to this code

Sorry no it wasnt supposed to be placed here, my apologies.

emadd commented

@michael-k-taylor You need to cancel the subscription in your widget's dispose method