riverpod
riverpod copied to clipboard
Documenting an approach for how to init some values before pushing a route
trafficstars
We need to find some reliable approach for initializing some values before pushing a route and add it to documentation.
There was a related issue #1329 that was asking for a way to auto dispose after first listener, which is one of the approaches to solve this matter. but as Remi mentioned, it seems dangerous, as if the "first listener" is never added for some reason, the disposal will never happen.
Another proposed approach is to do something like:
await ref.run(provider, (value) async {
// provider will stay alive until the callback completes
await Navigator.push(); // The await here will keep the provider alive until the route is poped
});
but this won't work with the common go_router's method .go as it's synchronous.
Note: There's an issue asking for it to be asynchronous, but it's there for a very long time.