简体   繁体   English

Flutter WEB:Firebase:没有 Z035489FF8D092741943E4A8'DEFA9 应用程序已创建

[英]Flutter WEB: Firebase: No Firebase App '[DEFAULT]' has been created

After adding these dependencies to my pubspec.yaml in my flutter WEB project在我的 flutter WEB 项目中将这些依赖项添加到我的 pubspec.yaml 之后

  firebase_auth: ^0.18.4+1
  cloud_firestore: ^0.14.4
  firebase_core: ^0.5.3

and these below to my web/index.html file这些在我的 web/index.html 文件下面

<script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-auth.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-firestore.js"></script>

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "xxxxxxxxxxxxxxxxxxxxxxxx",
    authDomain: "xxxxxxxxxxxxxxxxxxx",
    projectId: "xxxxxxxxxxxxxxxxxxxx",
    storageBucket: "xxxxxxxxxxxxxxxxx",
    messagingSenderId: "xxxxxxxxxxxxxxxx",
    appId: "xxxxxxxxxxxxxxxxxxx"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
</script>


when I try to rebuild the WEB app I get:当我尝试重建 WEB 应用程序时,我得到:

Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). Firebase: 否 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Firebase App.initializeApp() (app/no-app)。

any error related to this?与此相关的任何错误? additional error:附加错误:

FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
    at Object.f [as app] (https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js:1:16867)
    at Object.app$ [as app] (http://localhost:40783/packages/firebase_core_web/src/interop/core.dart.lib.js:32:101)
    at initializeApp (http://localhost:40783/packages/firebase_core_web/firebase_core_web.dart.lib.js:81:25)
    at initializeApp.next (<anonymous>)
    at runBody (http://localhost:40783/dart_sdk.js:37976:34)
    at Object._async [as async] (http://localhost:40783/dart_sdk.js:38007:7)
    at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:40783/packages/firebase_core_web/firebase_core_web.dart.lib.js:74:20)
    at initializeApp (http://localhost:40783/packages/firebase_core/firebase_core.dart.lib.js:122:59)
    at initializeApp.next (<anonymous>)
    at runBody (http://localhost:40783/dart_sdk.js:37976:34)
    at Object._async [as async] (http://localhost:40783/dart_sdk.js:38007:7)
    at Function.initializeApp (http://localhost:40783/packages/firebase_core/firebase_core.dart.lib.js:121:20)
    at main$ (http://localhost:40783/packages/vibeland/widgets/subscription_widget.dart.lib.js:9807:36)
    at main$.next (<anonymous>)
    at runBody (http://localhost:40783/dart_sdk.js:37976:34)
    at Object._async [as async] (http://localhost:40783/dart_sdk.js:38007:7)
    at main$ (http://localhost:40783/packages/vibeland/widgets/subscription_widget.dart.lib.js:9805:18)
    at main (http://localhost:40783/web_entrypoint.dart.lib.js:34:27)
    at main.next (<anonymous>)
    at http://localhost:40783/dart_sdk.js:37956:33
    at _RootZone.runUnary (http://localhost:40783/dart_sdk.js:37810:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:40783/dart_sdk.js:32771:29)
    at handleValueCallback (http://localhost:40783/dart_sdk.js:33319:49)
    at Function._propagateToListeners (http://localhost:40783/dart_sdk.js:33357:17)
    at async._AsyncCallbackEntry.new.callback (http://localhost:40783/dart_sdk.js:33082:27)
    at Object._microtaskLoop (http://localhost:40783/dart_sdk.js:38071:13)
    at _startMicrotaskLoop (http://localhost:40783/dart_sdk.js:38077:13)
    at http://localhost:40783/dart_sdk.js:33574:9

For Flutter web, There is a new setup for Firebase Plugins.对于 Flutter web,有一个针对 Firebase 插件的新设置。
First of All, follow all the steps mentioned here https://firebase.flutter.dev/docs/installation/web首先,按照这里提到的所有步骤https://firebase.flutter.dev/docs/installation/web

the below file is web/index.html下面的文件是web/index.html

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>example</title>
</head>
<body>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
  <script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
  <script>
    // Your web app's Firebase configuration
    var firebaseConfig = {
        apiKey: "...",
        authDomain: "[YOUR_PROJECT].firebaseapp.com",
        databaseURL: "https://[YOUR_PROJECT].firebaseio.com",
        projectId: "[YOUR_PROJECT]",
        storageBucket: "[YOUR_PROJECT].appspot.com",
        messagingSenderId: "...",
        appId: "1:...:web:...",
        measurementId: "G-...",
      };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  </script>
  <script src="main.dart.js" type="application/javascript"></script>
  <script>
    var serviceWorkerVersion = null;
    var scriptLoaded = false;
    function loadMainDartJs() {
      if (scriptLoaded) {
        return;
      }
      scriptLoaded = true;
      var scriptTag = document.createElement('script');
      scriptTag.src = 'main.dart.js';
      scriptTag.type = 'application/javascript';
      document.body.append(scriptTag);
    }

    if ('serviceWorker' in navigator) {
      // Service workers are supported. Use them.
      window.addEventListener('load', function () {
        //register firebase-messaging service worker
        navigator.serviceWorker.register("/firebase-messaging-sw.js");
        // Wait for registration to finish before dropping the <script> tag.
        // Otherwise, the browser will load the script multiple times,
        // potentially different versions.
        var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;

        navigator.serviceWorker.register(serviceWorkerUrl)
          .then((reg) => {
            function waitForActivation(serviceWorker) {
              serviceWorker.addEventListener('statechange', () => {
                if (serviceWorker.state == 'activated') {
                  console.log('Installed new service worker.');
                  loadMainDartJs();
                }
              });
            }
            if (!reg.active && (reg.installing || reg.waiting)) {
              // No active web worker and we have installed or are installing
              // one for the first time. Simply wait for it to activate.
              waitForActivation(reg.installing ?? reg.waiting);
            } else if (!reg.active.scriptURL.endsWith(serviceWorkerVersion)) {
              // When the app updates the serviceWorkerVersion changes, so we
              // need to ask the service worker to update.
              console.log('New service worker available.');
              reg.update();
              waitForActivation(reg.installing);
            } else {
              // Existing service worker is still good.
              console.log('Loading app from service worker.');
              loadMainDartJs();
            }
          });

        // If service worker doesn't succeed in a reasonable amount of time,
        // fallback to plaint <script> tag.
        setTimeout(() => {
          if (!scriptLoaded) {
            console.warn(
              'Failed to load app from service worker. Falling back to plain <script> tag.',
            );
            loadMainDartJs();
          }
        }, 4000);
      });
    } else {
      // Service workers not supported. Just drop the <script> tag.
      loadMainDartJs();
    }
  </script>
</body>
</html>

View this setup at https://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging/firebase_messaging/example/webhttps://github.com/FirebaseExtended/flutterfire/tree/master/packages/firebase_messaging/firebase_messaging/example/web查看此设置

Initialize it in the main() method在 main() 方法中初始化它

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}
Error: Assertion failed: file:///G:/flutter_sdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_core_web-1.5.3/lib/src/firebase_core_web.dart:273:11
options != null
"FirebaseOptions cannot be null when creating the default app."
    at Object.throw_ [as throw] (http://localhost:56114/dart_sdk.js:5374:11)
    at Object.assertFailed (http://localhost:56114/dart_sdk.js:5296:15)
    at firebase_core_web.FirebaseCoreWeb.new.initializeApp (http://localhost:56114/packages/firebase_core_web/firebase_core_web.dart.lib.js:253:42)
    at initializeApp.next (<anonymous>)
    at http://localhost:56114/dart_sdk.js:40646:33
    at _RootZone.runUnary (http://localhost:56114/dart_sdk.js:40503:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:56114/dart_sdk.js:35432:29)
    at handleValueCallback (http://localhost:56114/dart_sdk.js:36017:49)
    at Function._propagateToListeners (http://localhost:56114/dart_sdk.js:36055:17)
    at _Future.new.[_completeWithValue] (http://localhost:56114/dart_sdk.js:35897:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:56114/dart_sdk.js:35920:35)
    at Object._microtaskLoop (http://localhost:56114/dart_sdk.js:40808:13)
    at _startMicrotaskLoop (http://localhost:56114/dart_sdk.js:40814:13)
    at http://localhost:56114/dart_sdk.js:36279:9

暂无
暂无

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

相关问题 Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - Flutter Web - No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) flutter web:否 Firebase 应用程序“[DEFAULT]”已创建 - 调用 Z035489FF8D092741AF943E.Fialize83() - flutter web: No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in FlutterFire FirebaseError: Firebase: No Firebase App &#39;[DEFAULT]&#39; has been created - 启用 web flutter 时调用 Firebase App.initializeApp() (app/no-app) - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) when enable web flutter FirebaseError: Firebase: 否 Firebase App '[DEFAULT]' 已创建 - 调用 Firebase App.initializeApp() {颤动网络} - FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app). {Flutter web} Flutter Web - Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - Flutter Web - Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) Flutter and Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) - Flutter and Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app) “没有创建 Firebase App '[DEFAULT]'”尽管调用了“initializeApp()”(Flutter、Firebase) - "No Firebase App '[DEFAULT]' has been created" despite "initializeApp()" has been called (Flutter, Firebase) 没有创建 Firebase App '[DEFAULT]' - 在 Flutter 和 Firebase 调用 Firebase.initializeApp() - No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() in Flutter and Firebase 错误:未创建 Firebase 应用“[DEFAULT]” - Error: No Firebase App '[DEFAULT]' has been created Angular 2中尚未创建Firebase应用“ [DEFAULT]” - No Firebase App '[DEFAULT]' has been created in Angular 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM