[Question] Cleaning up state on beam away
tinaroh opened this issue · comments
Hello, I'm trying to find the best way to clean up some state if a user beams away from the page.
My setup is similar to bottom_navigation_multiple_beamers with nested Beamers, except my ArticleDetailsScreen is a StatefulWidget that contains an audio player.
The app preserves the state of the Articles "stack" when the user taps away (which I like), but because it's still in the widget tree, I'm having trouble figuring out where to handle clean up on navigation away.
If the user taps on the "Books" bottom navigation while the audio player is playing, I'm looking to declare and call something like ArticleDetailsScreen.onHide()
to pause the audio player and clean up some state. Is there a place like that?
Currently I'm thinking of having ArticleDetailsScreenState implement a onHide
and adding a routeListener
at the AppScreen level that calls it by accessing the state using a GlobalKey as mentioned here https://stackoverflow.com/a/46545141. But I wanted to see if there was a cleaner way through the library.
Thank you for the help!