尝试获取文档 ID 时出错

时间:2021-03-20 16:35:19

标签: firebase flutter google-cloud-firestore

IM 试图在 Flutter 中获取数据的文档 ID。但我收到此错误:


======== Exception caught by widgets library =======================================================
The following NoSuchMethodError was thrown building:
Class 'QueryDocumentSnapshot' has no instance getter 'docId'.
Receiver: Instance of 'QueryDocumentSnapshot'
Tried calling: docId

When the exception was thrown, this was the stack: 
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:54:5)
#1      Messages.build.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:project/seitenleiste/nachrichten.dart:425:50)
#2      SliverChildBuilderDelegate.build (package:flutter/src/widgets/sliver.dart:455:22)
#3      SliverMultiBoxAdaptorElement._build (package:flutter/src/widgets/sliver.dart:1213:28)
#4      SliverMultiBoxAdaptorElement.createChild.<anonymous closure> (package:flutter/src/widgets/sliver.dart:1226:55)

====================================================================================================

IM 使用 for 在 firebase 更新我的小部件时不会出错。 如果您需要更多代码,希望任何人都可以提供帮助,请发表评论。

1 个答案:

答案 0 :(得分:0)

几个月后,文档 ID 被称为 id 而不是 docId

我强烈建议在开发时将插件的参考文档放在手边,因为在 QueryDocumentSnapshot 的文档中很容易找到此类问题。