[英]Firebase is not getting initialized right
So, I wanted to include firebase into my Flutter App, it works fine for android but when I start it on my ios emulator it will always give me this error So, I wanted to include firebase into my Flutter App, it works fine for android but when I start it on my ios emulator it will always give me this error
[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
[VERBOSE-2:ui_dart_state.cc(209)] 未处理的异常:[core/not-initialized] Firebase 尚未正确初始化。 Usually this means you've attempted to use a Firebase service before calling
Firebase.initializeApp
.通常这意味着您在调用
Firebase.initializeApp
之前尝试使用 Firebase 服务。 View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization查看文档以获取更多信息: https://firebase.flutter.dev/docs/overview#initialization
I have the google-service file in the right directory and I followed the tutorial and edited my main() to:我在正确的目录中有 google-service 文件,我按照教程并将我的 main() 编辑为:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
Has anybody the same problem with IOS or did I do anything wrong?有人与 IOS 有同样的问题,还是我做错了什么?
So for everybody else getting this error I figured it out myself, for IOS, the line因此,对于其他遇到此错误的人,我自己想通了,对于 IOS,行
Firebase.initializeApp()
it needs an option:它需要一个选项:
Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform)
for that follow the instructions on this link:为此,请按照此链接上的说明进行操作:
https://firebase.flutter.dev/docs/cli https://firebase.flutter.dev/docs/cli
hope that helps anyone希望对任何人都有帮助
dart pub global activate flutterfire_cli
.dart pub global activate flutterfire_cli
。 Once installed, the flutterfire command will be globally available.flutterfire configure
in your flutter project folder in terminal,flutterfire configure
,WidgetsFlutterBinding.ensureInitialized(); if (Platform.isIOS) { await Firebase.initializeApp( options: DefaultFirebaseOptions.currentPlatform, ); } else { await Firebase.initializeApp(); } runApp( const MaterialApp( home: MyApp(), ), );
I got same problem.我遇到了同样的问题。 My Android application is working fine but when using IOS application it's throw this type of exception.
我的 Android 应用程序运行良好,但在使用 IOS 应用程序时会抛出此类异常。 you can use @Viki's answer and if its not working for you make sure you have added
GoogleServices-info.plist
file in your ios project.您可以使用@Viki 的答案,如果它不适合您,请确保您在 ios 项目中添加了
GoogleServices-info.plist
文件。 If it's not solve your issue then use this code如果它不能解决您的问题,请使用此代码
if (Platform.isIOS) {
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: "your api key Found in GoogleService-info.plist",
appId: "Your app id found in Firebase",
messagingSenderId: "Your Sender id found in Firebase",
projectId: "Your Project id found in Firebase"));
} else {
await Firebase.initializeApp();
}
I have faced the same issue in my flutter application when run on xcode/ ios.在 xcode/ios 上运行时,我在 flutter 应用程序中遇到了同样的问题。 Here is how I solved.
这是我解决的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.