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.
Rather not fix it yourself? App Fix Ticket starts with a fixed-price diagnosis, then a fixed price for the fix before any fix work.
Where Firebase wasn’t initialized, and the fix
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());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}"); }03
The configuration file is out of date
Simon also checks 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.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.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. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
“Very responsive, attentive to fixing bugs, and completed the project as needed! Thank you!”
Related: Flutter APNS token has not been set · Flutter pod install failed · Firebase app/duplicate-app · Firebase storage/no-default-bucket