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. Usually this means you've attempted to use a Firebase service before calling
Firebase.initializeApp
. View the documentation for more information: 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:
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?
So for everybody else getting this error I figured it out myself, for IOS, the line
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
hope that helps anyone
flutterfire configure
in your flutter project folder in terminal,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. 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. 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();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.