dispose method
The framework calls this method when this StateX object will never build again and will be disposed of with garbage collection.
Implementation
@protected
@override
@mustCallSuper
void dispose() {
/// The State object's lifecycle is terminated.
/// **IMPORTANT** You will not know when this will run
/// It's to the Flutter engines discretion. deactivate() is more reliable.
/// Subclasses should override deactivate() method instead
/// to release any resources (e.g., stop any active animations).
/// Indicate this State object is terminated.
disposed = true;
// No 'setState()' functions are allowed to fully function at this point.
_setStateAllowed = false;
for (final listener in _beforeList) {
listener.dispose();
}
for (final con in _controllerList) {
con.dispose();
}
// Clear the its list of Controllers
_disposeControllerListing();
for (final listener in _afterList) {
listener.dispose();
}
// Clear the 'listeners'
_disposeStateEventList();
// Remove any 'StateXController' reference
_controller = null;
// Clear the list of Controllers.
_cons.clear();
// // *In some cases, the setState() will be called again! gp
_setStateAllowed = true;
// In some cases, if then reinserted back in another part of the tree
// the build is called, and so setState() is not necessary.
_setStateRequested = false;
super.dispose();
}