Doing something when a widget leaves the screen

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.





unmount() isn't defined in StatefulWidget.
– SteAp
12 mins ago







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.

Popular posts from this blog

Visual Studio Code: How to configure includePath for better IntelliSense results

Spring cloud config client Could not locate PropertySource

Makefile test if variable is not empty