0

Hello im new to firebase.

I have 3 collections

Users: - userid

Providers: - Providerid - providerName - providerEmail

FavoriteProvider: - docId(userId+providerId) - userId - providerId

So, i have succeed put a favorite provider for a user and the user can have many favorite providers.

But how to get a stream list of favorite providers of that user in one list.

I tried using this code

Stream<List<SerProviders>> get favoriteProviders{
   favoriteProvidersCollectionRef.where('userId', isEqualTo: uid).snapshots.map(providerListfromsnapshot)
}

The function providerListfromssnapshot returns a list of providers according to model a created in flutter.

List<SerProvider> providerListfromssnapshot(QuerySnapshot snapshot) {
Return snapshot.docs.map((doc){
   Var data = doc.data() as Map<String, dynamic>;
Return SerProvider(
  ProviderId: doc.id,
  ProviderName: data['providerName'] 
);}).toList();
}

But no idea how to complete.

I need the data of the provider (id and name) in that stream.

Anyone help me plzzz

esraakd
  • 21
  • 6
  • It looks like you're trying to [join data from two collections](https://stackoverflow.com/questions/59061225/how-do-i-join-data-from-two-firestore-collections-in-flutter). I'd specifically have a look at this answer with a [custom stream builder](https://stackoverflow.com/a/59097364/209103), or the answer [using RxDart](https://stackoverflow.com/a/59191174/209103). – Frank van Puffelen Apr 17 '22 at 14:18
  • i really can't understand the answer , can u answer my question according to my code? – esraakd Apr 18 '22 at 09:55

0 Answers0