flutter query multiple collections in firestore

前端 未结 1 1325
北荒
北荒 2021-02-15 15:12

I am playing with flutter but I ran into an issue with firestore that I can\'t figure out.

let\'s say I would like to retrieve the purchaser history of a customer and I

相关标签:
1条回答
  • 2021-02-15 15:46

    Short answer i didn't pay attention to how you use a future

    Get the productId from the user table

      Future<List<DocumentSnapshot>> getProduceID() async{
        var data = await Firestore.instance.collection('users').document(widget.userId).collection('Products').getDocuments();
        var productId = data.documents;
        return productId;
      }
    

    Then call this using .then() rather than try to apply the returned data to the variable as that is not how a future it works

      var products;
      getProduceID().then((data){
      for(int i = 0; i < s.length; i++) {
        products = Firestore.instance.collection('products')
            .document(data[i]['productID'])
            .snapshots();
        if (products != null) {
          products.forEach((product) {
            print(product.data.values);
          });
        }
      }
    });
    
    0 讨论(0)
提交回复
热议问题