Flutter
Root hooks and ownership
Attach Flutter framework and platform callbacks without replacing another owner silently or producing duplicate incidents.
Root hooks and ownership
FlutterError.onError receives framework-caught failures from build, layout, paint, callbacks, and explicit FlutterError.reportError calls. PlatformDispatcher.onError receives unhandled root-isolate errors outside those framework callbacks when no nearer Zone consumes them.
FlutterErrorManagerBinding attaches both paths:
final FlutterErrorManagerBinding binding =
FlutterErrorManagerBinding(manager: manager)..attach();
Ownership is explicit:
- repeated
attachon the same binding is idempotent; - a second active binding throws
StateError; detachrestores callbacks captured during attach;- a callback installed later by another owner is not overwritten;
- child-isolate errors require
IsolateErrorManagerBinding.
FlutterPreviousErrorHandlerPolicy.preserve invokes the previous callback after manager submission. This retains Flutter's normal debug output. Use replace only after deliberately moving the previous behavior elsewhere.
Do not preserve a second remote crash reporter without a deduplication plan.