0

I have two collections

collections pdm:

enter image description here

I want to make a stream reads favorite providers for user

 Stream<List<FavoriteProvider>> get favoriteProviders{
    return favoriteProviderCollection.where('userID', isEqualTo: this.uid).snapshots()
      .map(_favoriteproviderListfromsnapshot);
  }

  List<FavoriteProvider> _favoriteproviderListfromsnapshot (QuerySnapshot snapshot){
     return snapshot.docs.map((doc){
      var data = doc.data() as Map<String, dynamic>;
      return FavoriteProvider(
        providerID: data['providerID'],
        userID: data['userID']
      );
    }).toList();
  }

but how to complete?

I tried this but it seems not good

final favoriteProviders = Provider.of<List<FavoriteProvider>>(context);
      return new StreamBuilder(
        stream: FirebaseFirestore.instance.collection('providers').doc(favoriteProviders).snapshots(),
        builder: (context, snapshot) {
          if (!snapshot.hasData) {
            return Container();
          }
          List<ServineraProvider> servineraProviders = snapshot.data;
          return ListView.builder(...)
}
);

any one can help me

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
esraakd
  • 21
  • 6
  • thery are 3 with the users collection but it is not important for the code – esraakd May 21 '22 at 13:47
  • What you are trying to do is called a "join" in database terminology. Firestore does not support join queries between collections for performance and scalability reasons. You will have to perform at least two separate queries (as you are now) in order to get what you want. – Doug Stevenson May 21 '22 at 14:25
  • oki can u help me im new to firebase – esraakd May 24 '22 at 06:54

0 Answers0