IntermediateFirebase Integration
How do you set up Firebase Crashlytics to catch Flutter errors?
Short Answer
Wire both FlutterError.onError (for framework/widget-build errors) and PlatformDispatcher.instance.onError (for uncaught async errors) to record errors to Crashlytics, since neither alone catches every category of error.
Flutter has two largely separate error channels: framework errors surface through FlutterError.onError, while errors in async code outside the framework's direct control need PlatformDispatcher.instance.onError (or the older runZonedGuarded pattern). Missing either means a whole category of production crashes never reaches Crashlytics.
A complete setup overrides both in main(), before runApp().
Code Example
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterFatalError;
PlatformDispatcher.instance.onError = (error, stack) {
FirebaseCrashlytics.instance.recordError(error, stack, fatal: true);
return true;
};
runApp(const MyApp());
}Common Mistakes
- ×Wiring only FlutterError.onError and assuming all crashes are covered — uncaught async errors need PlatformDispatcher.onError separately.
- ×Testing Crashlytics setup only in debug mode — reporting typically needs a real/release-like build and can be delayed in delivery.