Bloc: [Question] Optionally always listen to BlocListener state changes

Created on 12 Dec 2019  路  3Comments  路  Source: felangel/bloc

It would be handy to say if we want to always listen to state changes on BlocListener, and optionally override condition if we only want to trigger on new state changes.


To paint a picture -- in my case I have an intermediate widget with a BlocListener on the AuthenticationBloc with the sole purpose of performing pushReplacement routes to the Login or Home pages.

When the user logins successfully from the Login page, we'd dispatch an event to the AuthenticationBloc (i.e. change state from unauthenticated to authenticated), then we pushReplacement back to this intermediate widget which in turn triggers the BlocListener to route through to the Home page.

This no longer behaves like this due to BlocListener ignoring the first state (i.e. skip(1)).

question

Most helpful comment

Sorry for the delay! Happy for you to close this ticket :)

I'll create an example app to demonstrate how I was originally using it with navigation routes -- however in the interim I've used direct routes to the appropriate screens instead of routing back to the intermediate widget for re-routing.

All 3 comments

Hi @cmengler 馃憢
Thanks for opening an issue!

Regarding your question, BlocListener intentionally behaves like this because we don't consider the first state to be a state change. Would it be possible for you to share a link to a sample app which illustrates the problem you're having? I'm happy to take a look and offer suggestions 馃憤 thanks!

Closing for now since there isn't enough information provided. Feel free to comment with additional information or a link to a sample app and I'm happy to continue the conversation!

Sorry for the delay! Happy for you to close this ticket :)

I'll create an example app to demonstrate how I was originally using it with navigation routes -- however in the interim I've used direct routes to the appropriate screens instead of routing back to the intermediate widget for re-routing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

abinvp picture abinvp  路  3Comments

krusek picture krusek  路  3Comments

clicksocial picture clicksocial  路  3Comments

Reidond picture Reidond  路  3Comments

MahdiPishguy picture MahdiPishguy  路  3Comments