Initializing Firebase Throws an Error – Flutter

Issue

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 🙂

Answered By – Tushar Patel

Answer Checked By – Terry (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.