【问题标题】:Unhandled Exception: Bad state: field does not exist within the DocumentSnapshotPlatform未处理的异常:错误状态:DocumentSnapshotPlatform 中不存在字段
【发布时间】:2021-03-20 14:44:58
【问题描述】:

我正在尝试从我的集合中检索一组数据,但每次运行代码时都会出错:

“未处理的异常:错误状态:DocumentSnapshotPlatform 中不存在字段”,并且从 Firestore 中没有检索到任何内容。

代码如下:

class EnterRefferal extends StatefulWidget {
  @override
  _EnterRefferalState createState() => _EnterRefferalState();
}

class _EnterRefferalState extends State<EnterRefferal> {
  List<String> refId = [];
  void initState() {
    super.initState();
    FirebaseFirestore.instance
        .collection("clients")
        .get()
        .then((QuerySnapshot querySnapshot) => {
              setState(() {
                querySnapshot.docs.forEach((doc) {
                  refId.addAll([doc["refID"]]);
                });
              }),
            });
  }

  @override
  Widget build(BuildContext context) {
    print(refId);

请帮我解决这个问题,在此先感谢。

【问题讨论】:

  • 您的收藏在 Firestore 中是什么样的?
  • 错误消息表明您的clients 集合中没有名为refID 的字段。您能否分享您的 Firestore 结构,以便我们检查您要获取的内容?

标签: flutter google-cloud-firestore


【解决方案1】:

确保“客户”集合中存在“refID”字段。 试试这个,

使用 doc.get('refID') 或 doc.data()['refID']

代替 [文档[“refID”]]

【讨论】:

    猜你喜欢
    • 2021-03-05
    • 2023-01-11
    • 2021-10-26
    • 2021-05-16
    • 2021-10-27
    • 1970-01-01
    • 2021-09-28
    • 2021-09-27
    • 2021-05-16
    相关资源
    最近更新 更多