error: The setter 'observer' isn't defined for the type 'Bloc<Event, State>'

Viewed 60

I'm using flutter_bloc and according to this example I want to observe the bloc. but I get this error:

error: The setter 'observer' isn't defined for the type 'Bloc<Event, State>'. (undefined_setter at [login_bloc_project] lib\main.dart:12)

when calling this method:

void main() {
  Bloc.observer = MyBlocObserver();
  runApp(MyApp());
}

how can I fix this error?

1 Answers

You can try like this :

  BlocOverrides.runZoned(
    () => runApp(const MyApp()),
    blocObserver: MyBlocObserver(),
  );
Related