-
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Cleaning up state on beam away #647
Comments
I think the best way is to listen to it using the routeListener... |
@tinaroh you schould use inherited widget to manage that or even something like riverpod or bloc to manage your logic. GlobalKey is possible but not scalable |
Got it, thank you! |
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 arouteListener
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!
The text was updated successfully, but these errors were encountered: