-
-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More convenient Scoped Provider syntax #1289
Comments
The issue with this proposal is, this means overriding providers would use a different syntax based on whether the override is done in a widget or not Bear in mind that Riverpod's dependency on Flutter is optional. It's very much possible to use Riverpod without Flutter, and those cases also sometimes want to override providers. |
Overriding providers already use a different syntax depending on if it's in a widget or not. Doing it in flutter uses |
Both use the same syntax: overrides: [
someProvider.overrideWithValue(42),
] |
Ok, they both use the same |
Having multiple syntaxes for doing the same thing is generally a bad idea. Also, the current syntax scales better with overriding multiple providers at once. With your proposal, overriding multiple providers would involve quite a bit of nesting Similarly when overriding 2+ providers at once, the current syntax hosts the overrides within a single ProviderContainer. Whereas since proposal would involve creating once container per override, which is less efficient |
Again, I am NOT proposing you get rid of the current syntax. I'm simply proposing a syntactic sugar alternative for the use case of 1 override. There are many instances where only one override is necessary, and in instances where overriding 2+ providers then the current method should be used (and documentation should make it abundantly clear which is appropriate). The way I see it, it's akin to to Provider and MultiProvider - peaceful coexistence for slightly different use cases. |
I'll close this as I don't plan on implementing it. If you want this, you can still do it on your own with extensions. It's not as convenient as if I did it for you, but you still can have it. |
Is your feature request related to a problem? Please describe.
Whilst I like that Riverpod prevents unsafe reads from unscoped parts of the widget tree like in provider, being able to explicitly define scope within the widget tree is immensely useful, particularly when when dealing with having multiple different providers active in different parts of the screen, or having async dependencies on other providers.
I'm sure you're familiar with React's context API:
If a child component tries to access the context's value, if it is a child of the scoped provider, it gets
scopedValue
, otherwise it gets the defaultdefaultValue
.This is currently already possible with
ScopedProvider
:But in my opinion the syntax is a little clunky.
Describe the solution you'd like
Instead of the above syntax, it would be nice if we could instead do something like this:
Could call it
.Provider
,.createScope
, etc etc as well.The text was updated successfully, but these errors were encountered: