Replies: 1 comment
-
The problem certainly comes from using a WidgetRef in onData, since this ref will probably be invalidated once the Widget it comes from is disposed.
Perhaps there is also a "cleaner" way to organize all this. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey,
I´m still learning how to utilize riverpod and ran into a problem I just cannot solve.
My app is measuring volume levels and triggers recording on a condition. It works fine while the user stays on the Page which triggers the stream but i keep running into the "Unhandled Exception: Bad state: Cannot use "ref" after the widget was disposed." error, when i try to pop that page, the user should be able to navigate through the app while the process is still running.
I've tried to seperate the logic from the UI but have seemed to fail somewhere and just cannot wrap my head around how to solve this.
short breakdown of what it does:
starts listening to a stream, the callback function has a callback, in case of an event where noise threshold X was exceeded.
So here is my example code:
I've tried to minize the code:
frontend:
This is the NoiseMeter itself
The generation file for the providers:
And finally the function called to start measuring:
When navigating away from the page using navigator.pop, due to removing the frontend page from the tree, it throws the mentioned error at me. I do understand why but i just cannot figure out, how to kleep the stream and trigger functions "alive" while navigating through the app and after coming back to the frontend page, showing the current progress.
How to get rid of the dependency between my logic and the frontend page, is what's driving me crazy.
I've tried to create anything outside of the widget which is beeing disposed.
This is how i think my code is set up and why I thought my providers were indipendent from the frontend page.
In fact there is a lot of code which i left out but i was trying to keep it as short as possible and assume it is a problem with me not understandig how to properly seperate the NoiseMeter from the ui.
When pushing a new page insted of popping the current one, its working fine but i would prefer to keep the tree short and navigation straightforward, if possible.
In case I didn't meet the expectations how to ask questions, i already want to apologize, I`m a hobby programmer and might didn't understand this wasn't a riverpod issue, just the "ref" hinted me towards it. I've tried to google the issue and to ask LLM but couldn't find an answer which i was able to understand, or saw fitting for my specific issue.
Thanks in advance for help
Beta Was this translation helpful? Give feedback.
All reactions