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

问题描述 投票:0回答:1

我正在使用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);
  }```
flutter google-cloud-firestore stream provider
1个回答
0
投票

您是否尝试打印值并调试代码?

© www.soinside.com 2019 - 2024. All rights reserved.