When I start the flutter web app I get this error:
[core/not-initialized] Firebase has not been correctly initialized. Usually this means you've attempted to use a Firebase service before calling
Firebase.initializeApp.
<!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>
As you can see firebase is initialized in the index.html file. I have installed all the needed libraries, this is the list:
Should I init firebase in flutter?
if (kIsWeb)
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: "xxx",
appId: "xxx",
messagingSenderId: "xxx",
projectId: "xxx",
),
);
else
await Firebase.initializeApp();
Add the above code in your main.dart file. (kIsWeb will check whether the application is running on the web)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With