Fix "No Firebase App [DEFAULT] has been created" in Flutter
Fix the "No Firebase App [DEFAULT] has been created" error by correctly initializing the Firebase app before calling any Firebase services in Flutter.
TL;DR#
If you're seeing No Firebase App '[DEFAULT]' has been created - call Firebase.initializeApp(), the cause is usually that you're trying to use a Firebase service like Firestore, Auth, or Storage before initializing the Firebase app in your Dart code. Fix it by calling Firebase.initializeApp() in main() before runApp().
If that doesn't work, scroll to verify the fix because there are two common variants this guide also covers.
What you'll see#
FirebaseException: [core/no-app] No Firebase App '[DEFAULT]' has been created.
Call Firebase.initializeApp() before using any Firebase services.It happens when you try to use a Firebase service such as FirebaseFirestore.instance, FirebaseAuth.instance, or FirebaseStorage.instance before the app has been initialized. The behavior is the same across Android, iOS, and web in Flutter.
You'll see this error most often when:
- You add Firebase logic inside a widget's
build()orinitState()without ensuring initialization has completed. - You move Firebase calls into a separate service class and forget to await
initializeApp()before instantiating that class. - You update
main()and only use hot reload, so the initialization path never re-runs.
Root cause#
The root cause is simple but easy to miss: the Firebase SDK for Flutter does not auto-initialize the default app instance. You must explicitly call Firebase.initializeApp() and await it before accessing any Firebase service.
Under the hood, Firebase.initializeApp() registers a FirebaseApp instance named '[DEFAULT]' in the SDK's internal registry. When you later call FirebaseFirestore.instance, the SDK looks up that registry, and if it finds no '[DEFAULT]' app, it throws the error you're seeing.
The relevant code path is:
// lib/main.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
// WRONG: This line is missing or not awaited
// await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// This line throws the error if Firebase.initializeApp() hasn't run
final db = FirebaseFirestore.instance;
return MaterialApp(
home: Scaffold(
body: Center(
child: Text('Firestore instance: $db'),
),
),
);
}
}This fails because FirebaseFirestore.instance tries to access the default app before it's been registered. The same pattern applies to FirebaseAuth.instance, FirebaseStorage.instance, and any other Firebase service.
The error is not about missing credentials or misconfigured google-services.json. It is purely about initialization order. You can have perfect Firebase config files and still hit this error if initializeApp() is not called first.
The fix#
// lib/main.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
final db = FirebaseFirestore.instance;
return MaterialApp(
home: Scaffold(
body: Center(
child: Text('Firestore instance: $db'),
),
),
);
}
}That single change, adding await Firebase.initializeApp() in main() before runApp(), addresses the cause because it registers the default Firebase app instance before any service tries to access it.
Step by step#
- Open
lib/main.dart. - Import
firebase_coreif it's not already imported:import 'package:firebase_core/firebase_core.dart';. - Add
WidgetsFlutterBinding.ensureInitialized();at the top ofmain()so the Flutter engine is ready before async work. - Add
await Firebase.initializeApp();after the binding line. - Save and run
flutter run.
You must also ensure firebase_core and cloud_firestore are listed in pubspec.yaml:
dependencies:
flutter:
sdk: flutter
firebase_core:
cloud_firestore:Run flutter pub get after editing pubspec.yaml.
Verify the fix#
Run:
flutter runYou should see the app launch without the No Firebase App '[DEFAULT]' error, and the Firestore instance should print successfully in the UI.
If you want to be extra sure, add a debug log:
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
print('Firebase app initialized: ${Firebase.app().name}');
runApp(const MyApp());
}You'll see Firebase app initialized: [DEFAULT] in the console, confirming the app is registered.
If you're still seeing the error, two common variants exist:
Variant A - Using Firebase in a service class before initialization#
You might have a service class like this:
// lib/services/firestore_service.dart
import 'package:cloud_firestore/cloud_firestore.dart';
class FirestoreService {
final db = FirebaseFirestore.instance;
Future<void> saveData() async {
await db.collection('users').add({'name': 'Alice'});
}
}Then elsewhere you create the service before initialization finishes, or via a top-level singleton:
final service = FirestoreService();
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp(service: service));
}That variant fails because FirebaseFirestore.instance is touched while building the global service, before main() has completed initialization.
Fix: Delay the service's Firebase access until after initialization:
// lib/services/firestore_service.dart
import 'package:cloud_firestore/cloud_firestore.dart';
class FirestoreService {
FirebaseFirestore? _db;
Future<void> init() async {
_db ??= FirebaseFirestore.instance;
}
Future<void> saveData() async {
await _db!.collection('users').add({'name': 'Alice'});
}
}Then in main():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final service = FirestoreService();
await service.init();
runApp(MyApp(service: service));
}Variant B - Hot reload vs. hot restart#
Hot reload preserves the Dart VM state, so if you added await Firebase.initializeApp() after the app was already running, hot reload will not re-execute main(). The error may persist until you do a full restart.
Fix: Use hot restart after changing main(), not just hot reload.
Why this happens (and how to avoid it next time)#
The underlying invariant is simple: Firebase services require a registered app instance, and that instance must be created before any service accessor is called. Flutter's hot reload and Dart's initialization order make this easy to miss, especially when services are instantiated at the top level of a file.
Related#
- Supabase vs Firebase in 2026: The Honest Comparison No One Is Telling You
- Why Developers Are Switching from Firebase to Supabase (And You Should Too)
- How to Structure Your Next.js App Router Project for Scale
- Next.js Hydration Mismatch: 8 Fixes for App Router (2026)
- Next.js Pages to App Router Migration Gotchas
- Is It Safe to Expose Firebase API Key to the Public? Those resources cover the broader Firebase ecosystem and alternative backends if you want to compare Flutter + Firebase with other stacks once initialization is working reliably.