provider icon indicating copy to clipboard operation
provider copied to clipboard

Multiple providers of the same type can be registered

Open LuckyJayce opened this issue 2 years ago • 1 comments

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 image

In addition, write a class library to simplify the use of the provider https://github.com/LuckyJayce/provider_key

LuckyJayce avatar Feb 16 '22 10:02 LuckyJayce

If you extend InheritedScope, then Consumer/context.watch & co suddenly are unable to read the provider

How would you fix that?

rrousselGit avatar May 22 '22 09:05 rrousselGit

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!

rrousselGit avatar Oct 11 '22 07:10 rrousselGit