Doing something when a widget leaves the screen


Doing something when a widget leaves the screen
Suppose, I have a StatefulWidget, which periodically requests data from a server and this updates its state.
I prepared a Timer.periodic()
to make the data get loaded off the main loop.
Timer.periodic()
Now, if the widget leaves the screen, the Timer continues to call its callback.
What is the correct mount point to perform cleanup actions, when the widget get off the screen?
1 Answer
1
@override
void dispose() {
super.dispose();
...
}
You could also skip updates while mounted == false
mounted == false
See Flutter docs.
Just
dispose
was looking on the wrong class.– Günter Zöchbauer
10 mins ago
dispose
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
unmount() isn't defined in StatefulWidget.
– SteAp
12 mins ago