【问题标题】:flutter and firebase/firestore颤振和火力基地/火库
【发布时间】:2021-06-05 09:01:31
【问题描述】:

我是从 simone 的《flutter projects》一书中学习 Flutter(在 packt 上出版)。

我发现这段代码和书中的代码有点不同,因为现在一些关键字已经改变了(我猜)。

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

请帮助我哪里出错了。 并感谢您的帮助! ^^

【问题讨论】:

  • 你能检查调试控制台吗?有什么错误吗?
  • 不,实际上它必须打印在 firebase 网站上自动选择的 ID 或说文档 ID,你明白了吗,(是的,它打印空行而不是那个 ID,它没有'甚至不打印'现在在这里'行)。您需要屏幕截图或类似的东西吗?

标签: firebase flutter dart google-cloud-firestore


【解决方案1】:

最后我想出了如何解决,这与 Stackoverflow 上已回答的问题类似,如果您面临同样的问题并且还没有任何解决方案,那么这肯定会帮助您,至少它帮助了我。

只需导入 firebase 核心库,然后在 void main 中添加这一行。

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase

您可以在此处找到有关我遇到的问题的更多详细信息。

希望对你有帮助!!

【讨论】:

    猜你喜欢
    • 2021-03-10
    • 2021-03-19
    • 2021-07-03
    • 2021-02-03
    • 2020-06-26
    • 2023-03-22
    • 2020-07-28
    • 2020-11-04
    • 2016-09-17
    相关资源
    最近更新 更多