I am trying to run my app and it is giving the following error
[core/no-app] No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp()
I have already called firebase.initializeApp()
but still the error is same.
here is my code of main file
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (_) => AppointmentsProvider(),
child: MaterialApp(
title: 'Car Wash App',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: FutureBuilder(
future: Firebase.initializeApp(),
builder: (ctx, snap) =>
snap.connectionState == ConnectionState.waiting
? Center(
child: Text('Loading...'),
)
: StreamBuilder(
stream: FirebaseAuth.instance.authStateChanges(),
builder: (ctx, snapShot) =>
snapShot.hasData ? HomePage() : UserAuth(),
),
),
routes: {
HomePage.routeName: (_) => HomePage(),
HistoryPage.routeName: (_) => HistoryPage(),
MyAppointments.routeName: (_) => MyAppointments(),
PackagesPage.routeName: (_) => PackagesPage(),
VehicleType.routeName: (_) => VehicleType(),
SlotPage.routeName: (_) => SlotPage(),
ExtraServicesPage.routeName: (_) => ExtraServicesPage(),
SummaryPage.routeName: (_) => SummaryPage(),
DetailedScreen.routeName: (_) => DetailedScreen(),
PaymentMethodScreen.routeName: (_) => PaymentMethodScreen(),
},
),
);
}
}
Any kind of help is much appreciated. Thank you
initializeApp. Creates and initializes a Firebase app instance. See Add Firebase to your app and Initialize multiple projects for detailed documentation.
Creating and configuring a firebase projectHead over to Firebase console and add a new Firebase project, name it React Native Todo App . Once the project is set and ready, click Continue. You will be redirected to the console of that newly created project. React Native is cross-platform.
The firebase_core plugin is responsible for connecting your Flutter app to your Firebase project. The plugin must be installed and initialized before the usage of any other FlutterFire plugins. It provides basic functionality such as: Initializing FlutterFire. Creating Secondary Firebase App Instances.
Default app is initialized after the other one. Correct way is to initialize the default app first and then the rest. firebase.apps.app () is being called before default app initialization. This code is basically returning the default app instance. Since it is not present, hence the error.
In this way, you can solve "No Firebase App ' [DEFAULT]' has been created - call Firebase.initializeApp ()" error in the Flutter app.
Why this mattered for you is likely that code can implicitly use the default by eg. firebase.firestore () whereas with the custom "app" (first) the return value, an "app handle" must be passed around. I use both ways. The default for the main web app and the named variant within a library.
This error is caused when you use any Firebase services such as Cloud Messaging, Firestore without initializing Firebase core. Here, in our case, this error occurs while using Firebase cloud messaging. The cause of this error is you might not have initialized firebase before using firebase service, or you may have initialized like below:
You should initialise it in main().
For example:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
runApp(MyApp());
}
This link might be helpful for you.
If the above answers don't help, you can solve the problem by following steps:
delete the project and take backup of lib folder and pubspec.yaml file.
Create a new project with the same name
copy backed up files to the newly created project.
run flutter pub get
you are good to go
It literally solved my problem. I hope this will help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With