flutter / uxr

UXR work for Flutter
BSD 3-Clause "New" or "Revised" License
227 stars 28 forks source link

Using StreamGuards #73

Closed oodavid closed 2 years ago

oodavid commented 3 years ago

We have a permissions stream for our users. They may be have access granted or removed to different parts of our app.

A "StreamGuard" would allow us to update the state based on new information.

InMatrix commented 2 years ago

Cc a few package authors for their consideration / responses: @lulupointu @slovnicki @Milad-Akarie @tomgilder.

lulupointu commented 2 years ago

I'm not sure why you want to do this with a Stream. It might be simpler to have a state (which changes) which you then you to declaratively describe your routes (or your guards). The only place where you have to be careful is that when you detect a change, you might want to check if the current page is accessible and if not manually redirect.

Do check the sign-in scenarios are they represent the idea quite well in my opinion (in this scenario you have the AppState with one parameter but you could imagine replacing it by an AuthorizationState where many bools represent whether certain parts of the app can be accessed)

oodavid commented 2 years ago

Happy to provide examples to help with the why:

Abstract - the developer uses a realtime database for permissions, the app should react to changes in this state.

Concrete - In our enterprise app, admin users manage staff permissions. When this happens we re-render the route to show the "no permission, contact admin" or the permitted screen.

Thanks for the link to the sign-in scenarios

lulupointu commented 2 years ago

Feel free to close the issue if you think the sign-in scenarios provide a good solutions for your issue (as I think it does after your explanation).

If not, could you specify precisely which aspect of what you are trying to achieve differs and cannot be solved using the same logic?