Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Bloc listener is not listening after cubit emit new state #4219

Open
kjhamja77 opened this issue Jul 30, 2024 · 2 comments
Open

fix: Bloc listener is not listening after cubit emit new state #4219

kjhamja77 opened this issue Jul 30, 2024 · 2 comments
Assignees
Labels
question Further information is requested waiting for response Waiting for follow up

Comments

@kjhamja77
Copy link

Description
The Bloc listener is not listening for changes from the Authentication cubit but the Bloc builder got a new state and updated the UI based on the new state emitted from the cubit.

Steps To Reproduce

  1. Authentication cubit is set first with the init function that emits a new state based on the user ID, we store the user ID while logging, if the user ID is null, navigate to the login screen, if the user ID is not null, navigate to the home page.
  2. Gave bloc provider in the main function of my app class, and in my app class we defined the route in on generate route and home with the class in which we use bloc listener and bloc builder
  3. Bloc Builder got the state and it shows the UI based on the state, but the Bloc listener doesn't.

Expected Behavior
I need to navigate to the home page if the user ID is not null, else I need to navigate to the login screen.

Screenshots
kindly check the below screenshots
Screenshot 2024-07-30 130718
Screenshot 2024-07-30 130352
Screenshot 2024-07-30 130313

@kjhamja77 kjhamja77 added the bug Something isn't working label Jul 30, 2024
@tenhobi tenhobi added question Further information is requested waiting for response Waiting for follow up and removed bug Something isn't working labels Aug 15, 2024
@tenhobi tenhobi self-assigned this Aug 15, 2024
@tenhobi
Copy link
Collaborator

tenhobi commented Aug 15, 2024

It's hard to judge since you didn't show what is on the first screenshot and when in the widget tree you are using it. But my guess would be that you are expecting the widget with BlocListener and BlocBuilder (you can combine them using BlocConsumer btw) to work with the latest state of that bloc/cubit. But that is only true for the BlocBuilder, not for BlocListener. BlocListener works only with state changes, aka you must have the widget attached before the state changes to trigger the listener.

@nkalahanov
Copy link

You already provided cubit for the whole app, in your case, you don't need to provide the same cubit again, as we see per the first screenshot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested waiting for response Waiting for follow up
Projects
None yet
Development

No branches or pull requests

3 participants