Closed tinaroh closed 3 months ago
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!
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!