【问题标题】:How to store document field in a list using Dart如何使用 Dart 将文档字段存储在列表中
【发布时间】:2019-01-29 16:37:23
【问题描述】:

我正在尝试从文档中检索数组字段并将其存储在列表对象中。

到目前为止,这是我尝试过的:

   List<String> list;

Firestore.instance.collection("ingredients").document("Cutlet").get()
.then((snapshot) => list = snapshot.data["ingredients"]);

debugPrint("list is" + list.toString());
return list;

debugPrint 返回 null。

这是我的 Firestore 的快照。我正在尝试检索成分数组并将其存储在列表中。

【问题讨论】:

  • 然后尝试打印/返回里面的列表或者使用await

标签: dart flutter google-cloud-firestore


【解决方案1】:

试试这个

 DocumentSnapshot doc= await Firestore.instance.collection('ingredients').document('cutlet').get();
  if(doc.exists) {
    var list = doc['ingredients'].map<dynamic>((item) {
      return item;
    }).toList();
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-25
    • 2022-12-04
    • 2020-01-05
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多