should I still initialize firebase app twice in both index.html and main.dart if i am using only flutter web(no android or ios app)?

Viewed 97

I am trying to build an flutter app purely as a website then should i use firebase initialize app twice both in index.html and main.dart?

index.html

<script>
    // Your web app's Firebase configuration
    // For Firebase JS SDK v7.20.0 and later, measurementId is optional
    var firebaseConfig = {
      apiKey: "AIz...",
      authDomain: "...",
      databaseURL: "https://<project-name>.firebaseio.com",
      projectId: "...",
      storageBucket: "<project-name>.appspot.com",
      messagingSenderId: "...",
      appId: "...",
      measurementId: "..."
    };
    firebase.initializeApp(firebaseConfig);
    firebase.analytics();
  </script>

Main.dart

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

As mentioned in the docs here you should initialize it on both places.

As mentioned in the docs they are working on a way to initialize it just on one place:

We are actively investigating ways to initialize Firebase without directly using the CDN and will update the documentation once this becomes available.

Related