You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Firestore QuerySnapshot无documentID getter实例报错排查

报错原因

cloud_firestore 2.0(空安全适配版本)对API命名做了统一调整:

  • 1.x及更早的旧版本中,文档快照对象获取文档ID的属性名为documentID
  • 2.x及更新版本中,DocumentSnapshot、QueryDocumentSnapshot类下的文档ID属性被重命名为id,旧的documentID属性已被完全移除,直接访问就会触发「不存在对应getter」的运行时报错。
修复方法

将代码中访问documentID的位置替换为id属性即可,修改后的对应代码片段:

return BubbleMessage(
  key: ValueKey(doc[index].id), // 替换documentID为id
  message: doc[index]['message'],
  isMe: doc[index]['userId'] == user!.uid,
  username: doc[index]['username'],
);

如果项目其他位置存在读取Firestore文档ID的逻辑,也需要同步把documentID替换为id,避免出现同类错误。

内容的提问来源于stack exchange,提问作者oussama

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.29 20:54:25