23.3 C
New York
Wednesday, August 17, 2022

Flutter error: No Firebase App ‘[DEFAULT]’ has been created

- Advertisement -

Problem

When working with Flutter and Firebase, you may fall into the following error:

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

Solution

Before using any Firebase services, you have to initialize the Firebase app by calling Firebase.initializeApp(). Only one time, no more, no less.Advertisements

The solution to fix the mentioned problem and make sure it won’t happen again is quite simple. Everything you need to do is open the main.dart file and change from this:

void main(){
  runApp(MyApp());
}

To this:

// Import the Firebase Core package
import 'package:firebase_core/firebase_core.dart';

// Add async/await and 2 lines of code to the main function
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

If you call Firebase.initializeApp() somewhere else, remove it. After that, completely restart your Flutter app and check the result.

Further reading:

You can also take a tour around our Flutter topic page and Dart topic page to see the latest tutorials and examples.

Advertisements
- Advertisement -

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles