Hello Guys How are you all? hope you all are super fine. well whenever we use a firebase service-related plugin in a flutter project and then we get dependency, almost every developer would face this error Flutter Error: No Firebase App ‘[DEFAULT]’ has been created – call Firebase.initializeApp() in Flutter and Firebase.
I have decided to make all possible solution write down here so it will helpful for you. So without wasting your time lets start this article.
What Is Error:
══╡ EXCEPTION CAUGHT BY GESTURE ╞═══════════════════════════════════════════════════════════════════
The following FirebaseException was thrown while handling a gesture:
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
What Is Solution
Question: How to solve Flutter Error : No Firebase App ‘[DEFAULT]’ has been created – call Firebase.initializeApp() in Flutter and Firebase ?
Answer: Then we must have to call Firebase.initializeApp()
: in our app. same as like below.
Solution 1 :
Since August 2017 All Firebase service updated so you must have to call Firebase.initializeApp()
before using any Firebase product, for example:
We want to use firebase_core
plugin in flutter, then our pubspec.yaml
file will be same as below.
dependencies:
flutter:
sdk: flutter
firebase_core : ^0.5.0
Then we must have to call Firebase.initializeApp()
: in our app. same as like below.
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
Solution 2 :
pubspec.yaml
dependencies:
flutter:
sdk: flutter
firebase_core : ^0.5.0
Then we have to call Firebase.initializeApp()
: whenever you want to use.
import 'package:flutter/material.dart';
// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';
void main() {
runApp(App());
}
class App extends StatelessWidget {
@override
Widget build(BuildContext context) {
return FutureBuilder(
// Initialize FlutterFire
future: Firebase.initializeApp(),
builder: (context, snapshot) {
return Loading();
},
);
}
}
So, Guys both solutions are worked for me. let me know in the comment section if it is worked for you as well.
Also Read
- How to make a blur Background Image effect in Flutter using BackdropFilter.
- Create Rounded Corners Image in Flutter.
- How to change package name in flutter?