Replies: 1 comment 2 replies
-
If it's about doing: class A implements Interface {}
Provider<A>(create: (ctx) => A());
Provider.of<Interface>(context); // obtains A then no, this is not possible. But you could do: MultiProvider(
providers: [
Provider<A>(create: (ctx) => A()),
Provider<Interface>(create: (ctx) => ctx.read<A>()),
], |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I have a Provider which is the ancestor of another Provider, let's call it MyProvider, as they share a big part of their code.
When trying to get the MyProvider using Provider.of<MyProviderAncestor>(context, listen: false), the Provider will not be found causing a ProviderNotFoundError.
Is it correct that this Provider is not found even though it technically is of the same type?
The ancestor provider is part of a base which is shared with multiple apps and not to be used directly, but some of the code inside the base also needs to access this provider, and I obviously cannot put the actual provider type inside the base.
If this is indeed the correct behavior, can I somehow make it work differently? Something like Provider.of<extends MyProviderAncestor>(context, listen: false) etc.?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions