【问题标题】:Why is Cloud Firestore not working with flutter?为什么 Cloud Firestore 不能与颤振一起使用?
【发布时间】:2025-11-26 13:25:01
【问题描述】:

如果我添加这一行:final databaseReference = FirebaseFirestore.instance;

我收到此错误:

../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:42:29:错误:名称构造函数的名称必须与封闭类的名称匹配。 未来 tabs.add(Map data) async { ^^^^ ../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:42:3:错误:构造函数不能有返回类型。 尝试删除返回类型。 未来 tabs.add(Map data) async { ^^^^^^ ../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:46:5:错误:构造函数不能有返回类型。 尝试删除返回类型。 返回新文档; ^ ../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:42:71:错误:构造函数主体不能使用“异步”、“异步*”或“同步*”。 未来 tabs.add(Map data) async { ^ ../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:42:29:错误:最终字段“_delegate”未由此构造函数初始化。 尝试使用初始化形式或字段初始化程序来初始化字段。 未来 tabs.add(Map data) async { ^^^ ../../../../.pub-cache/hosted/pub.dartlang.org/cloud_firestore-0.14.4/lib/src/collection_reference.dart:11:37:上下文:“_delegate”已定义这里。 最终的 CollectionReferencePlatform _delegate; ^^^^^^^^^

【问题讨论】:

  • 你试过用flutter clean吗?
  • 是的,flutter clean 和 Invalidate caches / Restart。没有帮助。

标签: firebase flutter google-cloud-firestore


【解决方案1】:

删除flutter后重新下载。成功了

【讨论】:

  • 哇.. 太极端了.. 你试过运行flutter cleanflutter pub get 吗?
  • 删除 .pubcache 也可以
  • 是的,我尝试过 flutter clean 和 flutter pub get。但还没有尝试删除 .pubcache
最近更新 更多