尚未创建 Firebase 应用'[DEFAULT]' - 即使调用了 Firebase.InitializeApp(),错误仍然存在



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

未捕获(承诺中(Firebase错误:Firebase:未创建Firebase应用程序"[DEFAULT]"-调用Firebase App.initializeApp(((App/No-App(。

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

this my main.dart initial code

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>

当应用程序在本地正常运行时,但在发布模式下运行时,会生成以下错误。

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

您可以按照这里的firebase指南进行操作
还要确保检查您的google-services.json文件是否添加在android应用程序中,GoogleService-Info.plist是否添加在iOS应用程序中。

相关内容

  • 没有找到相关文章

最新更新