【问题标题】:No Firebase App '[DEFAULT]' has been created - Even when Firebase.InitializeApp() is called, the error persists没有创建 Firebase 应用“[DEFAULT]” - 即使调用 Firebase.InitializeApp(),错误仍然存​​在
【发布时间】:2021-04-11 20:34:56
【问题描述】:

我希望有人可以帮助我解决这个问题,我已经尝试了上面给出的所有示例,但是仍然显示相同的错误

Uncaught (in promise) FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - 调用 Firebase App.initializeApp() (app/no-app)。

在 Object.f [作为应用程序] (https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js:1:16867)

这是我的 main.dart 初始代码

void main() async {

WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  developer.log('${Firebase.apps.length}', name: 'main.dart');
  FlutterError.onError = (FlutterErrorDetails details) {
    FlutterError.dumpErrorToConsole(details);
  };
  runApp(App());
}

class App extends StatefulWidget {
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  
  @override
  Widget build(BuildContext context) {
    if(Firebase.apps.length == 0){
      return Loading();
    }
    else
    return StreamProvider<UserData>.value(
      value: AuthService().user,
      child: MaterialApp(
        title: MAIN_TITLE,
        debugShowCheckedModeBanner: false,
        theme: ThemeData(primarySwatch: Colors.amber, accentColor: Colors.amber[200]),
        home: MyHomePage(
          title: HOME_PAGE,
        ),
        routes: <String, WidgetBuilder>{
          '/home': (BuildContext context) => new Wrapper(),
        },
      ),
    );
  }
}

这是我的 index.html 文件

<!DOCTYPE html>
<html>
  <head>
    <base href="/" />

    <meta charset="UTF-8" />
    <meta content="IE=Edge" http-equiv="X-UA-Compatible" />
    <meta name="description" content="A new Flutter project." />

    <!-- iOS meta tags & icons -->
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="apple-mobile-web-app-title" content="web_product_unitrade" />
    <link rel="apple-touch-icon" href="icons/Icon-192.png" />

    <!-- Favicon -->
    <link rel="icon" type="image/png" href="favicon.png" />

    <title>web_product_unitrade</title>
    <link rel="manifest" href="manifest.json" />
       
  </head>
  <body>
    <p id="error-element"></p>
    <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-app.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.8.0/firebase-auth.js"></script>
     
    <script type="module">
      import { firebaseConfig} from '/lib/configuration/firebase-config.js';
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
      firebase.analytics();
    </script>
    <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-analytics.js"></script>
    <script src="https://www.gstatic.com/firebasejs/7.17.1/firebase-firestore.js"></script>
    <script src="https://www.gstatic.com/firebasejs/8.2.1/firebase-storage.js"></script>

    <script>
      if ("serviceWorker" in navigator) {
        window.addEventListener("flutter-first-frame", function () {
          navigator.serviceWorker.register("flutter_service_worker.js");
        });
      }
    </script>
    <script src="main.dart.js" type="application/javascript"></script>
  </body>
</html>

应用在本地运行正常,但是在release模式下运行,会产生如下错误。

zone.dart:1171 Uncaught 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.afQ (http://localhost:52254/main.dart.js:9835:63)
    at Object.ald (http://localhost:52254/main.dart.js:8221:29)
    at http://localhost:52254/main.dart.js:14458:5
    at afM.a (http://localhost:52254/main.dart.js:4531:71)
    at afM.$2 (http://localhost:52254/main.dart.js:29996:23)
    at Object.L (http://localhost:52254/main.dart.js:4517:19)
    at Object.P9 (http://localhost:52254/main.dart.js:14482:10)
    at http://localhost:52254/main.dart.js:71366:8
    at http://localhost:52254/main.dart.js:71361:55

【问题讨论】:

  • 使用 Flutter web,如果你更新 index.html,你可能需要关闭整个应用程序并运行 "flutter clean" 然后 "flutter packages get".... 另一个建议,尝试更改 @987654326 @ 到 firebasejs/7.20.0/firebase-app.js 因为这就是 Flutter Fire 网站上的 Flutter Web introduction 上显示的内容
  • @Uni 你能指定缺少哪个json文件吗??
  • @osaxma 我已经更改了 firebase-app.js 包,但仍然显示相同的错误。我确实尝试过flutter clean然后flutter run错误仍然存​​在

标签: firebase flutter web flutter-web


【解决方案1】:

您可以通过 here 遵循 firebase 指南。
还要确保检查您的 google-services.json 文件是否已添加到 android 应用中,而 GoogleService-Info.plist 是否已添加到 iOS 应用中。

【讨论】:

  • 是的,我已经按照使用 Flutter 构建 Web 应用程序的说明进行操作。
猜你喜欢
  • 2021-12-29
  • 2020-04-30
  • 1970-01-01
  • 2020-05-21
  • 1970-01-01
  • 2023-01-20
  • 2020-12-24
  • 2020-12-12
相关资源
最近更新 更多