【发布时间】:2021-09-30 05:12:59
【问题描述】:
所以我试图用 firebase 制作一个颤振应用程序,它工作得非常好,但是当我运行应用程序时,我收到了这个错误:
════════ Exception caught by widgets library ═══════════════════════════════════
The following FirebaseException was thrown building _BodyBuilder:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
The relevant error-causing widget was
Scaffold
package:app_with_firebase/main.dart:14
When the exception was thrown, this was the stack
#0 MethodChannelFirebase.app
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:122
#1 Firebase.app
package:firebase_core/src/firebase.dart:54
#2 FirebaseAuth.instance
package:firebase_auth/src/firebase_auth.dart:37
#3 new AuthService
package:app_with_firebase/Services/auth.dart:4
#4 new _LoginPageState
package:app_with_firebase/main.dart:29
...
════════════════════════════════════════════════════════════════════════════════
但问题是我的代码中有那行:
//import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'Services/auth.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
Firebase.initializeApp();
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: LoginPage(),
),
),
);
}
我怎样才能摆脱这个?该应用程序运行良好,但非常分散注意力,感谢任何帮助。
【问题讨论】:
-
你能添加 await Firebase.initializeApp();相反,我怀疑构建是在 Firebase 调用完成之前调用的
-
@Einzeln,谢谢!我在 Firebase.initializeApp() 前面添加了 await ,现在它就像一个魅力!
标签: firebase flutter dart firebase-realtime-database firebase-authentication