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

simultaneous emit #2602

Closed
railsonsm opened this issue Jul 15, 2021 · 7 comments
Closed

simultaneous emit #2602

railsonsm opened this issue Jul 15, 2021 · 7 comments
Assignees
Labels
question Further information is requested
Projects

Comments

@railsonsm
Copy link

Hello everybody.

I have a scenario here and would like your help. I'm putting together a page where I have a loader that shows when loading data. Soon after the data is loaded, the load is expected to disappear. The problem is that the emit with the data is not running.

`emit(RecordLoadState());

var either = await recordService.listRecords(
  competence!.month,
  competence!.year,
);

either.fold((l) {
  // emit(RecordErrorState(AppException("")));
}, (list) {
  **emit(RecordDataState(list));**
});

emit(RecordLoadedState());

`

The RecordDataState not emit

@felangel felangel self-assigned this Jul 15, 2021
@felangel felangel added question Further information is requested waiting for response Waiting for follow up labels Jul 15, 2021
@felangel
Copy link
Owner

Hi @railsonsm 👋
Thanks for opening an issue!

I'm guessing the state is not changing because it is being mutated. Check out the FAQs for more information and if you're still having trouble please provide a minimal reproduction sample that illustrates the issue, thanks!

@felangel felangel added this to To do in bloc via automation Jul 15, 2021
@railsonsm
Copy link
Author

railsonsm commented Jul 16, 2021

Thank you for the quick response.

I uploaded a project to git to show the mentioned scenario.

As in my project, I also didn't have the RecordDataState emit

https://github.com/railsonsm/bloc_state_test

@narcodico
Copy link
Contributor

@railsonsm your model should also extend Equatable.

@railsonsm
Copy link
Author

railsonsm commented Jul 20, 2021

@narcodico I had already taken this test. Wouldn't it take different instances to emit a new state?

@felangel felangel removed the waiting for response Waiting for follow up label Jul 27, 2021
@felangel
Copy link
Owner

felangel commented Aug 7, 2021

@narcodico I had already taken this test. Wouldn't it take different instances to emit a new state?

You need to always emit a new instance rather than mutating the existing state. If you want different instances of state with the same values to trigger state changes (and rebuilds) then you should avoid extending Equatable. You can check out the FAQ for more info on this.

Let me know if that helps 👍

@felangel felangel added the waiting for response Waiting for follow up label Aug 7, 2021
@felangel
Copy link
Owner

Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation 👍

bloc automation moved this from To do to Done Aug 12, 2021
@felangel felangel removed the waiting for response Waiting for follow up label Aug 12, 2021
@railsonsm
Copy link
Author

railsonsm commented Aug 26, 2021

Oops @felangel! I came back here haha. I continued with the scenario pointed out above, but going back to this subject I ended up finding this question. By placing a delay, emits occur as expected. Is there any barrier on the block that prevents it from issuing states so fast?

my code:

`

  test() async {
      emit(RecordLoadState("opa"));
  
      await Future<void>.delayed(const Duration(milliseconds: 10));
  
      var list = await getRecords();
  
      emit(RecordDataState(list));
  
      await Future<void>.delayed(const Duration(milliseconds: 10));
  
      emit(RecordLoadedState("dd"));
  }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
bloc
  
Done
Development

No branches or pull requests

3 participants