Skip to content

Flutter and Firebase errorFlutter: “No Firebase App ‘[DEFAULT]’ has been created”

The Flutter app crashes on launch, or when a push notification arrives in the background, with No Firebase App [DEFAULT] has been created, call Firebase.initializeApp(). Some Firebase code ran before Firebase was set up. Here’s where initialization belongs, from Firebase’s setup guide, or hand it over at a fixed price.

Short answer

Call WidgetsFlutterBinding.ensureInitialized(), then await Firebase.initializeApp() with DefaultFirebaseOptions.currentPlatform, all before runApp. If the crash happens when a message arrives in the background, call Firebase.initializeApp() inside the background message handler too, as Firebase’s own example does.

Where Firebase wasn’t initialized, and the fix

  1. 01

    main() doesn’t await initializeApp before runApp

    “Also in your lib/main.dart file, initialize Firebase using the DefaultFirebaseOptions object exported by the configuration file:” Firebase, Add Firebase to your Flutter app

    Any Firebase call before initialization finishes fails with this error, including one in a widget that builds on the first frame. Make main async and initialize first, exactly as Firebase’s setup guide shows:

    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp(
      options: DefaultFirebaseOptions.currentPlatform,
    );
    runApp(const MyApp());
  2. 02

    The background message handler doesn’t initialize

    “Since the handler runs in its own isolate outside your applications context, it is not possible to update application state or execute any UI impacting logic.” Firebase, Receive messages in a Flutter app

    On Android, a message that arrives while the app is in the background runs your handler in its own isolate, which doesn’t share the setup done in main. Firebase’s own example initializes at the top of the handler:

    @pragma('vm:entry-point')
    Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
      // If you're going to use other Firebase services in the background, such as Firestore,
      // make sure you call `initializeApp` before using other Firebase services.
      await Firebase.initializeApp();
      print("Handling a background message: ${message.messageId}");
    }
  3. 03

    The configuration file is out of date

    We also check that firebase_options.dart matches the project and platforms you build for. Firebase’s guide says to run flutterfire configure so the configuration stays up to date, then rebuild.

Checked against the vendor’s docs on : Firebase docs: Add Firebase to your Flutter app; Firebase docs: Receive messages in a Flutter app.

Rather hand it over?

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

Related: Flutter APNS token has not been set · Flutter pod install failed · Unexpected Gemini API charges on Firebase · Firestore quota exceeded

Questions

More on this error

Why does it only crash sometimes?

If initializeApp isn’t awaited, whether Firebase is ready in time depends on how fast the device starts the app. Awaiting it before runApp makes the order fixed.

Does it matter where Firebase.initializeApp is called?

Yes. Firebase’s setup guide calls it in main() before runApp, and its background handler example calls it again inside the handler.

Can you fix it for me?

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.

A different error?

Describe it and get a written quote

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; we reply by email, usually within one business day.