Firebase has not been correctly initialized Flutter for WEB ONLY

Viewed 88

In new fresh project, cannot connect to Firestore. Created Firestore project and added this code to index.html last inside body tag

<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-analytics.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
const firebaseConfig = {
  apiKey: "xxxxx",
  authDomain: "xxxxxxx.firebaseapp.com",
  projectId: "xxxx-xxxxx",
  storageBucket: "xxxxxxx.appspot.com",
  messagingSenderId: "xxxxxx",
  appId: "x:xxxxxxx:web:xxxxxxxxxxx",
  measurementId: "xxxxxxxxxxxxxx"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);

In pubspec.yaml added cloud_firestore dependency In flutter code

 StreamBuilder(
            stream:
                FirebaseFirestore.instance.collection('xxxx').snapshots(),
 ...

Get Firebase has not been correctly initialized error

0 Answers
Related