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

Updated: March 23, 2023 By: A Goodman Post a comment
Table Of Contents

Problem

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

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

Don’t panic. We will tackle this bug.

Solution

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

The solution to fix the mentioned problem and make sure it won’t happen again is quite simple. All 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.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles