简体   繁体   English

如果我只使用 flutter web(没有 android 或 ios 应用程序),我还应该在 index.html 和 main.dart 中两次初始化 firebase 应用程序吗?

[英]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?我正在尝试构建一个纯粹作为网站的 Flutter 应用程序,那么我应该在 index.html 和 main.dart 中两次使用 firebase 初始化应用程序吗?

index.html索引.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 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.正如此处docs中所述您应该在两个地方对其进行初始化。

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.我们正在积极研究在不直接使用 CDN 的情况下初始化 Firebase 的方法,并将在可用时更新文档。

暂无
暂无

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

相关问题 当我在 void main() 中初始化应用程序 firebase 时,它会为 web 抛出错误,但它与 android 一起工作正常 - When I initialize app firebase in void main() its throws an error for the web but its works fine with android How do I use Firebase.dart with Firebase Emulators FireStore db in a Flutter Web app? - How do I use Firebase.dart with Firebase Emulators FireStore db in a Flutter Web app? 即使 Web 版本 100% 不同,我是否应该在同一个 Flutter 项目中为 android 和 iOS 拥有应用程序的 Web 版本? - Should I have the web version of an app in the same Flutter project for android and iOS, even though the web version is 100% different? 我应该为 iOS 应用创建 Firestore 索引吗 - Should I create Firestore index for iOS app 错误:main.dart 中未定义名称“Firebase” - ERROR : Undefined name 'Firebase' in main.dart Flutter main.dart 中的 LateInitialization 错误 - LateInitialization Error In Flutter main.dart 在 Flutter 网页和移动应用中使用 Firebase - Use Firebase in both Flutter web AND mobile app 'firebase/main.dart':断言失败 - 'firebase/main.dart': Failed assertion 我是否必须在 Android Studio 和 Firebase 控制台 Z2567A5EC3005EB7AC2CZ948 中将我的应用程序链接到 Firebase? - Do I have to link my app to Firebase in both Android Studio and Firebase Console web? 为什么我无法将我的 flutter iOS 应用程序添加到我的 firebase 项目中? - Why am I unable to add my flutter iOS app to my firebase project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM