onDeactivated method
Called before the view is deactivated.
When the view is in this context, it means that the view is about to be extracted from the widget tree, but it may be
added again. Quoting the view deactivate
docs from https://api.flutter.dev/flutter/widgets/State/deactivate.html
:
In some cases, the framework will reinsert the State object into another part of the tree
(e.g., if the subtree containing this State object is grafted from one location in the tree to another).
If that happens, the framework will ensure that it calls build to give the
State object a chance to adapt to its new location in the tree.
So, this may be the correct lifecycle to remove any resources that depend on other widgets in the widget tree.
Usage:
class MyController extends Controller {
@override
void onDeactivated() => print('View is about to be deactivated and maybe disposed');
}
Implementation
@visibleForOverriding
void onDeactivated() {}