Bloc: mapEventToState after currentState removal

Created on 25 Mar 2019  ·  5Comments  ·  Source: felangel/bloc

I am getting "'AuthenticationBloc.mapEventToState' ('(AuthenticationState, AuthenticationEvent) → Stream') isn't a valid override of 'Bloc.mapEventToState' ('(AuthenticationEvent) → Stream').". It seems like the latest set of commits removed currentState from Bloc.mapEventToState, but the exampels still show using currentState with no other changes. I haven't tried building this, but I can't see how it would build.

How am I meant to get the currentState now?

question

Most helpful comment

Works great, thank you!

All 5 comments

@QoLTech what examples are you referring to? Everything should be updated to use the latest version bloc.

currentState is a property that you can access on all blocs.

For example, here. You removed the currentState from the method signature, but continue to use it in the method body.

You're saying that you can get currentState now without including it in the signature?

Okay, so I can access currentState without it needing to be in the signature.

However, I now have this issue and I'm not sure if it's related.

In my mapEventToState method, I could do this:

if (currentState is DocumentSuccessful) {
yield DocumentSuccessful(document: currentState.document);
}

I now have to do this:

if (currentState is DocumentSuccessful) {
  yield DocumentSuccessful(document: (currentState as DocumentSuccessful).document);
}

After checking the type of currentState, it allowed me to continue using currentState as if it was the DocumentSuccessful type which has the document property on it. I can no longer do so and I have to manually use 'as'. Do you know why this is?

@QoLTech the currentState in the method body is the bloc property. That's how it should be in v0.11.0 of bloc.

The error you're running into is because currentState is a computed property. You can do something like:

final _currentState = currentState;
if (_currentState is DocumentSuccessful) {
  yield DocumentSuccessful(document: _currentState.document);
}

Hope that helps 👍

Works great, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nhwilly picture nhwilly  ·  3Comments

1AlexFix1 picture 1AlexFix1  ·  3Comments

ricktotec picture ricktotec  ·  3Comments

komapeb picture komapeb  ·  3Comments

timtraversy picture timtraversy  ·  3Comments