exampleMainSentry function
void
exampleMainSentry()
RECOMMENDED main() — dreamic owns the handlers; main() wraps runApp in the guarded zone and (Path A′) installs the early web-JS handlers.
Implementation
void exampleMainSentry() async {
/*
// The guarded zone is the OUTERMOST thing in main(). All boot steps — STARTING
// with WidgetsFlutterBinding.ensureInitialized() — run INSIDE it: the binding
// must be initialized in the SAME zone runApp runs in (runGuarded forks a child
// runZonedGuarded zone, and Flutter logs a "Zone mismatch" warning if
// ensureInitialized() ran in a different zone). Running the rest of boot in-zone
// also routes any setup-time error through the chokepoint. (If your pre-runApp
// setup needs an `await`, make the body `() async { ... }` — the future is
// fire-and-forget and the zone still owns its errors.)
DreamicErrorHandling.runGuarded(() {
WidgetsFlutterBinding.ensureInitialized(); // boot step 1 (FIRST, in-zone)
installEarlyErrorHandlers(); // boot step 2
// boot step 3 — Path A′ ONLY (gated by the consumer's kWebDartCapture):
// install the Dart window 'error'/'unhandledrejection' listeners as the sole
// web capture surface. Omit under Path C. No-op on mobile.
if (kWebDartCapture) {
DreamicErrorHandling.installEarlyWebErrorHandlers();
}
// boot step 4 — register the reporter. managesOwnErrorHandlers: false (dreamic
// installs the handlers); requiresFirebase: false (Sentry attaches BEFORE
// Firebase for maximal startup coverage, incl. web).
configureErrorReporting(
ErrorReportingConfig.customOnly(
reporter: SentryErrorReporter(dsn: AppConfig.sentryDsn),
enableOnWeb: true,
),
);
// boot step 5 — run the app in this SAME zone. onError defaults to
// DreamicErrorHandling.recordZoneError, so this is all that's needed.
runApp(DreamicAppInitHost(
initFutureFactory: () => dreamicBootstrap(/* firebaseOptions, hooks, ... */),
splash: const DreamicSplash(),
child: const MyApp(),
));
});
// dreamicBootstrap() runs appInitErrorHandling() behind the splash: it calls
// initialize() (initializing Sentry), attaches the reporter, registers the
// isolate listener, and flushes the early buffers (breadcrumbs-then-errors).
*/
}