runWithReporterAndUiErrors function

void runWithReporterAndUiErrors(
  1. Reporter reporter,
  2. void block(
    1. Stream<UiGlobalError> uiErrors
    )
)

Handles global errors and sends them to reporter and async of UiGlobalError.

Designed to wrap the whole main() function. WARNING! FlutterWidgetsBinding.ensureInitialized() must be called inside it, otherwise some errors may not be caught.

Implementation

void runWithReporterAndUiErrors(Reporter reporter, void Function(Stream<UiGlobalError> uiErrors) block) {
  final controller = StreamController<UiGlobalError>.broadcast();
  final handler = GlobalErrorHandler.combine([ReporterGlobalErrorHandler(reporter), _UiGlobalErrorHandler(controller)]);
  runWithErrorHandler(handler, () => block(controller.stream));
}