Best practices for returning a provider from a provider? #1066
-
final userProvider = StreamProvider.autoDispose.family<User, String>((ref, userId) {
// ...Returns the User stream
});
final companyProvider = StreamProvider.autoDispose.family<Company, String>((ref, companyId) {
// ...Returns the Company stream
});
final userCompanyProvider = StreamProvider.autoDispose.family<Company?, String>((ref, userId) {
String? companyId = ref.watch(userProvider(userId).select((user) => user.value?.company!.id));
// ...What do I do here?
}); In the last provider, I want to return data from the first provider conditionally. Is the following reasonable?: final userCompanyProvider = Provider.autoDispose.family<Company?, String>((ref, userId) {
String? companyId = ref.watch(userProvider(userId).select((user) => user.value?.company!.id));
if (companyId != null) {
return ref.watch(companyProvider(companyId)).asData?.value;
}
}); I expected to create another StreamProvider (ie: returning the AsyncData). Provider seems to work, but not sure if I've missed something here? |
Beta Was this translation helpful? Give feedback.
Answered by
rrousselGit
Jan 6, 2022
Replies: 1 comment 2 replies
-
I do not understand what this is about. But conditionally watching a provider is fine |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
oodavid
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I do not understand what this is about. But conditionally watching a provider is fine