Bloc: The method 'dispatch' isn't defined for the class 'Bloc'.

Created on 23 Oct 2019  ·  4Comments  ·  Source: felangel/bloc

Describe the bug
After update to 1.0.0, the dispatch() function is not defined.

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple bloc with simple event
  2. Dispatch that event.

Expected behavior
I am heavy bloc user. My flutter app contain around 7 blocs and it works fine until today. After I update to 1.0.0, all of my dispatch() function got method is undefined error.

Screenshots
If applicable, add screenshots to help explain your problem.

*Logs *
error • The method 'dispatch' isn't defined for the class 'MainBloc' • lib/Profile/profile.dart:107:29 • undefined_method
error • The method 'dispatch' isn't defined for the class 'AuthenticationBloc' • lib/Profile/profile.dart:159:48 • undefined_method

Paste the output of running flutter doctor -v here.

Additional context
I am using StreamSubscription too and its Bloc.state.listen() too got Method is undefined error.

question

Most helpful comment

Hi @sooonism👋
Thanks for opening an issue!

There were core api changes introduced into 1.0.0:
bloc.state.listen -> bloc.listen
bloc.currentState -> bloc.state
bloc.dispatch -> bloc.add
bloc.dispose -> bloc.close

Check out https://link.medium.com/qnfMcEcW00 for more details.
Hope that helps 👍

All 4 comments

Hi @sooonism👋
Thanks for opening an issue!

There were core api changes introduced into 1.0.0:
bloc.state.listen -> bloc.listen
bloc.currentState -> bloc.state
bloc.dispatch -> bloc.add
bloc.dispose -> bloc.close

Check out https://link.medium.com/qnfMcEcW00 for more details.
Hope that helps 👍

Got the same error:

Compiler message:
lib/blocs/login/login_bloc.dart:54:30: Error: The method 'dispatch' isn't defined for the class 'AuthenticationBloc'.
 - 'AuthenticationBloc' is from 'package:tascout_app/blocs/authentication/authentication_bloc.dart' ('lib/blocs/authentication/authentication_bloc.dart').
Try correcting the name to the name of an existing method, or defining a method named 'dispatch'.
          authenticationBloc.dispatch( LoggedIn(token: user.token));
                             ^^^^^^^^
Target kernel_snapshot failed: Exception: Errors during snapshot creation: null
Failed to build bundle.

Hi @sooonism👋
Thanks for opening an issue!

There were core api changes introduced into 1.0.0:
bloc.state.listen -> bloc.listen
bloc.currentState -> bloc.state
bloc.dispatch -> bloc.add
bloc.dispose -> bloc.close

Check out https://link.medium.com/qnfMcEcW00 for more details.
Hope that helps 👍

Okay, u have changed with add

:clap:

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shawnchan2014 picture shawnchan2014  ·  3Comments

timtraversy picture timtraversy  ·  3Comments

ricktotec picture ricktotec  ·  3Comments

wheel1992 picture wheel1992  ·  3Comments

frankrod picture frankrod  ·  3Comments