Closed yiss closed 3 years ago
Another proposition for it could be :
final listener1 = ProviderListener(
provider: provider1,
onChange: (context, value) {},
);
final listener2 = ProviderListener(
provider: provider2,
onChange: (context, value) {},
);
final listener3 = ProviderListener(
provider: provider3,
onChange: (context, value) {},
);
return MultipleListener(
listeners: [listener1, listener2, listener3], child: Container());
This issue may same as https://github.com/rrousselGit/river_pod/issues/163
Have a look at the hooks implementation useProvider
.
Widget build(context) {
final fooState = useProvider(foo.state);
final barState= useProvider(bar.state);
final bazState = useProvider(baz.state);
return Container();
}
Or why dont you just nest ProviderListeners?
@quangson91 Thank you for pointing that out, I didn't see it. But yeah useProviderListener
would solve this for me since I use Hooks, but the problem is that some people use river_pod without Hooks. @smiLLe use provider would not suffice here cause you'll have to manage provider change manually for every provider and again not all the people use hooks, nesting ProviderListeners is the current solution but it really gets messy after three nested providers
This sounds similar to #67. I made a comment on this here with a link to a gist where i make a new provider by adding a list of providers and combine them. I'm quite new to riverpod so not sure if this is a good solution though..
Closing in favor of #335
I am waiting for this feature. So, I am currently using this way. It's working for me.
ProviderListener(
provider: authNotifierProvider,
onChange: (context, state) {
},
child: ProviderListener(
provider: tenantCatLogNotifierProvider,
onChange: (BuildContext context, value) {
},
child: Consumer(builder: (context, watch, child) {
final state = watch(tenantCatLogNotifierProvider);
final authState = watch(authNotifierProvider);
return IgnorePointer(
ignoring: state is TenantCatLogLoading || authState is AuthLoading,
child:);
}),
)
),
@rrousselGit Hey, can you give me this way is okay or it is bad practice?
ProviderListener is really good the only problem is that it only listen to one provider at time. my question is that would there be a solution for having a MultipleProviderListener where it listens to multiple provider and fires the
onchange
callback every-time one of these providers is changed.Example :
Is this a something that can be achieved ? and how is the performance going to be affected ? Thank you again!