provider
provider copied to clipboard
Multiple providers of the same type can be registered
I want to be able to register the same type of provider, I know that river_pod does this, but I want the provider implementation. My solution is to create different _InheritedProviderScope subclass objects if the same type is encountered
class _Inh0<T> extends _InheritedProviderScope<T> {
}
class _Inh1<T> extends _InheritedProviderScope<T> {
}
class _Inh2<T> extends _InheritedProviderScope<T> {
}
class _Inh3<T> extends _InheritedProviderScope<T> {
}
And Provider.of to get data through different _InheritedProviderScope subtypes
inheritedElement = context.getElementForInheritedWidgetOfExactType<
_Inh0<T?>>() as _InheritedProviderScopeElement<T?>?;
inheritedElement = context.getElementForInheritedWidgetOfExactType<
_Inh1<T?>>() as _InheritedProviderScopeElement<T?>?;
inheritedElement = context.getElementForInheritedWidgetOfExactType<
_Inh2<T?>>() as _InheritedProviderScopeElement<T?>?;
To this end, I implemented a simplified version of the provider verification scheme, the code is linked below
https://github.com/LuckyJayce/provider_same_type
In addition, write a class library to simplify the use of the provider https://github.com/LuckyJayce/provider_key
If you extend InheritedScope, then Consumer/context.watch & co suddenly are unable to read the provider
How would you fix that?
In the lack of a reply, I'll close this.
If you still have an idea on how to move forward, I'd be happy to see that!