riverpod icon indicating copy to clipboard operation
riverpod copied to clipboard

Documenting an approach for how to init some values before pushing a route

Open AhmedLSayed9 opened this issue 1 year ago • 6 comments
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.

AhmedLSayed9 avatar Oct 07 '24 22:10 AhmedLSayed9