How to solve: No Firebase App has been created - call Firebase.initializeApp()


Asked by Flutter B on December 26, 2021 (source).

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() {

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => AppointmentsProvider(),
      child: MaterialApp(
        title: 'Car Wash App',
        theme: ThemeData(
          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


Question answered by Adil N (source).

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 hepl.

Video Answers on YouTube