lucavenir / go_router_riverpod

An example on how to use Riverpod + GoRouter
460 stars 68 forks source link

Suggested approach with more than one provider to watch? #7

Closed spakanati closed 1 year ago

spakanati commented 1 year ago

I have multiple providers that I need to watch to determine whether redirects are needed (e.g. auth provider, email verification provider, etc.). In that scenario using the new sync example, my screen visibly flashes when rebuilding multiple times. I did read the README section about how most rebuilds aren't what they seem, but it seems the current approach may only be meant for a single provider at a time? When I remove everything but a single auth provider the behavior is as expected and there is no flickering or visible rebuilding. Is there a suggested approach or any examples showing how to watch more than one provider? Should I create a combined provider that has every bit of state/property the router needs for its redirect? Thanks so much for making this repo!

lucavenir commented 1 year ago

Sure.

I'll try to address this ASAP. Specifically, it depends on the use case, but maybe we can show off a even "more complete" example in which multiple states need to be listened to.

Unluckily, I am very busy at the moment. I need to ask either for your patience (it's gonna take time) or for a PR to be reviewed and merged. Consider that I had the intention to update the examples using code generation, since that's the direction both Riverpod and GoRouter are taking at the moment.

spakanati commented 1 year ago

Thanks for the response! As a temporary workaround, I did end up creating a provider that has all the state I need for my redirect logic and then listening only to that one provider. When I get a chance, I'll test https://github.com/lucavenir/go_router_riverpod/pull/8 to see if that makes multiple listeners possible.

lucavenir commented 1 year ago

Hi again. I just updated the master branch, with several hotfixes. I wanted to fix some issues, to better document my choices and to simplify the codebase.

You can check the answer to your question in the new notifier I created, here (read the build method).

If you have more questions, please let me know.