Having trouble calling Bloc.observer in main.dart

Issue

enter image description here

When I call Bloc.observer in main.dart, it doesn’t work

Solution

You can run it through zone guarded

Runs body in its own error zone.

Creates a new zone using Zone.fork based on zoneSpecification and zoneValues, then runs body in that zone and returns the result.

 await runZonedGuarded(
    () async {
      await BlocOverrides.runZoned(
        () async => runApp(MyApp()),
        blocObserver: AppBlocObserver(),
      );
    },
    (error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
  );

Answered By – griffins

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *