如何从Flutter Firestore中的嵌套集合中获取数据?

时间:2020-01-13 05:46:58

标签: flutter google-cloud-firestore stream provider

我正在使用providerStream从Firestore提取数据。所以现在我想访问内部集合。但我无法获取数据。我如何访问myOrders集合。 这就是消防站的结构。 enter image description here

enter image description here

我尝试获取此代码,但对我不起作用。

//Store data into myOrders collection

  Future myOrders(String image, String price) async {
    final FirebaseUser user = await _auth.currentUser();
    return await userData
        .document(user.uid)
        .collection('myOrders')
        .document()
        .setData({
      'orderedImage': image,
      'orderedPrice': price,
    });
  }
    // get the data as snapshot

  List<OrderedModel> myOrderSnapShot(QuerySnapshot snapshot) {
    return snapshot.documents.map((doc) {
      return OrderedModel(
          orderedImage: doc.data['orderedImage'] ?? '',
          orderedPrice: doc.data['orderedPrice']);
    }).toList();
  }

   // get the snapshot as stream

  Stream<List<OrderedModel>> get orderedStream {
    return userData.document(uid).collection('myOrders').snapshots().map(myOrderSnapShot);
  }```

1 个答案:

答案 0 :(得分:1)

您尝试打印这些值并调试代码吗?