简体   繁体   中英

No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp() -Flutter

I'm developing a note-taking app (Android app) that uses Firebase, So I intend to add Firebase Authentication. I created the app on Firebase console.

I'm taking an error, as you can see at the image down below:

这是错误信息

I tried some fixes, that I found at Stack Overflow.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  await Firebase.initializeApp();
  
  runApp(const MyApp());
}

This is the main function in main.dart

I guess I'm missing a spot. But I can't find it.

How can I solve this problem?

For Flutter android if you are initializing Firebase with just

Firebase.initializeApp();

without passing any arguments to the initializeApp function (ie firebase configuration/api keys of your project), then you need to add the google-services.json inside the android/app/ folder and add some code in build.gradle files so the app knows where to take project configuration from.

The recommended way though is to use the flutterfire_cli package to handle downloading all the necessary configuration files and adding required code to initialize Firebase for your flutter app.

Follow these steps:

  1. Go to https://console.firebase.google.com/
  2. Select your project
  3. On the project overview page you would see a Add app button

Firebase 控制台添加应用按钮

  1. Click on it and choose the Flutter option

在此处输入图像描述

  1. Then follow the step shown on screen and you'll be good

do you have firebase_core dependencie in your pubspec.yaml?? if not: install firebase_core and import it in your main file.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM