首页 > 解决方案 > 颤振和火力基地/火库

问题描述

我是从 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

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

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


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

只需导入 firebase 核心库,然后在 void main.

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

没有创建 Firebase 应用“[DEFAULT]” - 在 Flutter 和 Firebase 中调用 Firebase.initializeApp()

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

希望这对你有帮助!


推荐阅读