Search code examples
firebaseflutterdartflutter-android

Initializing Firebase Throws an Error - Flutter


While I was trying to set up Firebase, I learned that I need to initialize Firebase after the last updates. But when I run:

Firebase.initializeApp();

I get an error saying:

_CastError (Null check operator used on a null value)

I tried to remove it, afterwords everything worked fine. This is the code I am running:

Future<void> main() async {
  await Firebase.initializeApp();
  runApp(SignIn());
}

Solution

  • According to documents this is how you can initialize firebase in your app:

    Future<void> main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(); //Make sure you imported firebase_core
      runApp(SignIn());
     );
    }
    

    Happy Fluttering :)