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

In flutter development, sometimes we need to use firebase services like firebase Cloud Messaging, Cloud Firestore, and Google Analytics, etc. sometimes may have seen this firebase common error Error No Firebase App ’[DEFAULT]’ has been created. The error behind this error is might not have initialized firebase before using the firebase service, Let's see how to solve this type of error.

 

Error : 

E/flutter (10040): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] 
Unhandled Exception: [core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
E/flutter (10040): #0      MethodChannelFirebase.app 
(package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:149:5)
E/flutter (10040): #1      Firebase.app (package:firebase_core/src/firebase.dart:55:41)
E/flutter (10040): #2      FirebaseMessaging.instance (package:firebase_messaging/src/messaging.dart:32:47)

 

Solution :

We need to initialize the firebase before using any firebase services so first, we need to add the latest package of firebase_core  in pubspec.yaml file like below the example.

 

dependencies:
  flutter:
    sdk: flutter
  firebase_core: ^2.4.0

 

After adding the firebase_core package we need to initialize the firebase in main.dart like below the example.

import 'package:firebase_core/firebase_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  //initilization Firebase app
  await Firebase.initializeApp();
  
  
  runApp(MyApp());
}

 

Finally, we have initialized Firebase using Firebase.initializeApp() method in the main method. The most important thing, this is a Future method, So don't forget to add "await" before Firebase.initializeApp(), otherwise, you will get the same error.

In this way, we can easily solve "No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()" error in the Flutter.

I hope this post will help you.

Tags: