Replies: 3 comments 2 replies
-
I don't know riverpod 1.0 but there is a migration guide to the new api. final exampleProvider = Provider<BaseNotifierClass>((ref) => throw UnimplementedError('')); which would remove the family provider. You can then instantiate different subclasses with a ProviderScope return ProviderScope(
overrides: [
baseProvider.overrideWithValue(SubClass())
]
child: WidgetThatExpectsBaseClass(),
); This is also shown by the todo example. |
Beta Was this translation helpful? Give feedback.
1 reply
-
It's not clear to me what you used to do with StateNotifier, so I'm not sure how to help. |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have a similar but more simple issue 3664. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently in the process of upgrading from Riverpod 1 to 2. I want to know how to subclass
Notifier
s and be able to override the notifier's provider with different subclasses of different variants (family vs non-family, for instance).In my current implementation, we have a handful of cases where we create a StateNotifier implementation T that provides a state S with additional methods to handle user interaction. There are cases where we subclass T (ST) and provide new constructor parameters and override methods or add additional functionality. Then, any widgets expecting T can be wrapped in a ProviderScope where we can override the provider of T with a new provider of ST. We can use
overrideWithValue
oroverrideWithProvider
where the provider types can be different as long as they both return a T and S (for instance, the base class provider can be non-family and a subclass can be a family).I have not figured out how to gain the same functionality with Notifier, since it seems the Notifier class is tightly coupled to the provider providing it.
For example, how could I do something like this with Riverpod 2s Notifier class?
This doesn't work for a few reasons:
Beta Was this translation helpful? Give feedback.
All reactions