Pass a closure ussing 'ref' to an object returned by a Provider #583
-
I have a The code: final providerA = StateNotifierProvider<NotifierA, StateA>(
(ref) => NotifierA(),
);
final providerB = StateNotifierProvider<NotifierB, StateB>(
(ref) => NotifierB(() => ref.read(providerA).fieldFromStateA),
);
It works great as far as I can tell. My question is whether it is safe to give another object a closure which captures Judging by the docs https://riverpod.dev/docs/concepts/combining_providers/#can-i-read-a-provider-without-listening-to-it it should be just fine, but this docs is for 0.14.x and I'm using 1.0.0-dev.x and maybe things changed? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This is fine. Although I would recommend passing |
Beta Was this translation helpful? Give feedback.
This is fine. Although I would recommend passing
ref
itself, so that NotifierB can callref.read(providerA)