D
DevOps & CI/CDMedium30 XP4 min read

How do you set up crash reporting and observability for Flutter apps?

TL;DR: Use Firebase Crashlytics or Sentry for crash reporting. Wrap runApp with FlutterError.onError and PlatformDispatcher.instance.onError to catch all unhandled errors. Log custom events and breadcrumbs for better crash context.

Full Answer

Without crash reporting, you learn about bugs from user reviews. With Crashlytics/Sentry, you see crashes in real time with stack traces, device info, and user impact.

Error Interception Points

  • FlutterError.onError: catches Flutter framework errors (setState on disposed widget, render exceptions)
  • PlatformDispatcher.instance.onError: catches Dart async errors not caught by Flutter
  • runZonedGuarded: catches all errors in the zone, including non-Flutter async errors
  • try/catch in async code: explicit handling for expected error paths
🎯

Combine crash reporting with custom logging: log breadcrumbs (user actions, API calls) before a crash so you can reconstruct what the user did leading up to the bug.

Code Examples

dartComplete crash reporting setup
Output
// FlutterError.onError: widget errors, render errors
// PlatformDispatcher.onError: async Dart errors
// runZonedGuarded: fallback for zone-unhandled errors
// All three together = complete error coverage

Common Mistakes

  • Only catching Flutter errors but not PlatformDispatcher.onError — async Dart errors outside the widget tree are missed
  • Not setting user identifiers — can't correlate crashes to users or reproduction steps

Interview Tip

💡

Show all three error intercept points. Many developers only know FlutterError.onError and miss the async path. Mentioning breadcrumb logging demonstrates production operations experience.

#crash-reporting#Firebase-Crashlytics#Sentry#observability#error-handling