简体   繁体   中英

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)?

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());
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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