firebase - 颤振和火力基地/火库
问题描述
我是从 simone 的书 flutter projects(发表于 packt)中学习 flutter 的。
而且我发现这段代码与书中的代码有些不同,因为现在更改了一些关键字(我猜)。
Future testData() async {
print('here'); // I can see this in debug
FirebaseFirestore db = FirebaseFirestore.instance; // book says Firestore instead of FirebaseFirestore
print('now here'); // but I can't see this , So, I think there is some issue with above lines.
var data = await db.collection('event_details').get(); // it has getDocuments()
var details = data.docs.toList(); //it has documents instead of docs
details.forEach((d) {
print(d.id); // it has documentID rather than just id
});
}
输出应该是类似于“nasfs3rasfsd...”的 ID
请帮助我哪里出错了。并感谢您的帮助!^^
解决方案
最后我想出了如何解决,这是一个类似于 Stackoverflow 上已经回答的问题的问题,如果你面临同样的问题并且还没有任何解决方案,那么这肯定会帮助你,至少它帮助了我.
只需导入 firebase 核心库,然后在 void main.
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用 Firebase.initializeApp()
在这里您可以找到有关我遇到的问题的更多详细信息。
希望这对你有帮助!
推荐阅读
- google-drive-api - 如何恢复意外从共享谷歌驱动器中删除的文件
- xml - 如何让 git Merge 知道冲突的对象 ID
- angular - 如何防止单击 angular-fontawesome 图标重定向到默认页面
- java - 无法在 rest api 中使用 InputStream 上传多个文件
- azure - 将任务的输出复制到文件并将其存储在 Azure DevOps 管道中的 azure 工件中
- android - 如何拥有 2 个参数化 sharedViewModel 实例?
- centos - Certbot SSL 证书问题
- java - 将字符串列表传递给声明的类文件
- laravel - 如何将多个文件从 Vuejs 和 Vuex 上传到 Laravel?
- python - 如何使用 python 变量作为参数从 python 脚本调用 bash 脚本并设置 pid