繁体   English   中英

Flutter web Firebase 初始化错误

[英]Flutter web Firebase initialization error

当我启动颤振网络应用程序时,我收到此错误:

[核心/未初始化] Firebase 未正确初始化。 通常这意味着您在调用Firebase.initializeApp之前尝试使用 Firebase 服务。

<!DOCTYPE html>
<html>
<head>
    ...
</head>
<body>
  <script type="module">
    // Import the functions you need from the SDKs you need
    import { initializeApp } from "https://www.gstatic.com/firebasejs/9.9.0/firebase-app.js";
    import { auth } from 'https://www.gstatic.com/firebasejs/9.9.0/firebase-auth.js'
    import { firestore } from 'https://www.gstatic.com/firebasejs/9.9.0/firebase-firestore.js'  
    // https://firebase.google.com/docs/web/setup#available-libraries
  
    // Your web app's Firebase configuration
    const firebaseConfig = {
      apiKey: "xxx",
      authDomain: "xxx",
      projectId: "xxx",
      storageBucket: "xxx",
      messagingSenderId: "xxx",
      appId: "xxx"
    };
  
    // Initialize Firebase
    const app = initializeApp(firebaseConfig);
  </script>  
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
         ...
  </script>
</body>
</html>

如您所见,firebase 已在 index.html 文件中初始化。 我已经安装了所有需要的库,这是列表:

  • firebase_auth:^3.4.2
  • cloud_firestore: ^3.3.0
  • firebase_core:^1.19.2

我应该在颤动中初始化firebase吗?

 if (kIsWeb) 
    await Firebase.initializeApp(
      options: FirebaseOptions(
        apiKey: "xxx",
        appId: "xxx",
        messagingSenderId: "xxx",
        projectId: "xxx",
      ),
    );
else
   await Firebase.initializeApp();

在你的 main.dart 文件中添加上面的代码。 (kIsWeb 会检查应用程序是否在网络上运行)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM