How to Solve No Firebase App Has Been Created??

· 2 min read
No Firebase App Has Been Created
No Firebase App Has Been Created

While Integrating Firebase you might have faced an error that says No Firebase App Has Been Created. Earlier We have been through Step By Step Guide to Integrate Firebase With Flutter.  Let’s go through how to deal with it.

How to Solve No Firebase App  Has Been Created – Call Firebase.initializeApp() in Flutter and Firebase ??

All Firebase versions have been updated and now you have to call Firebase.initializeApp() before using any Firebase product.

Firstly, all Firebase products now depend on firebase_core version 1.17.0+, therefore you need to add it in the pubspec.yaml file.

dependencies:
 flutter:
   sdk: flutter
 firebase_core : ^1.17.0

Then you have to call Firebase.initializeApp():

Import the firebase_core plugin like below:

import 'package:firebase_core/firebase_core.dart';

Now in an Initialize Firebase App like below:

import 'package:flutter/material.dart';

void main() {
  runApp(App());
}

class App extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire
      future: Firebase.initializeApp(),
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return SomethingWentWrong();
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MyAwesomeApp();
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Loading();
      },
    );
  }
}

Initialize it in initState() then call setState() which will call the build() method.

@override
void initState() {
  super.initState();
  Firebase.initializeApp().whenComplete(() { 
    print("completed");
    setState(() {});
  });
}

Initialize it in the main() method after calling WidgetsFlutterBinding.ensureInitialized();

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  runApp(MyApp());
}

Conclusion:

So in this article, we have learned about How to Solve No Firebase App Has Been Created.

Thanks for Reading!!!
Keep Learning!!! 

Do let us know if you need any assistance with Flutter Development:)

FlutterAgency.com is one of the most popular online portals dedicated to Flutter Technology and daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

2 comments

Leave a Reply