Flutter BlocConsumer builder only called once, but listener and BlocObserver see states changes as expected?

Viewed 273

I hope this is the right place to ask this question. I'm using Bloc 8.0 and noticed that if an event handler is emitting multiple state changes very quickly, BlocListener and BlocObserver "catch" all the state changes, but BlocBuilder only catches the last one.

To be clear - I can confirm my bloc changes states correctly, this is not a problem of emitting the same state and bloc is not updating (like in many other questions about bloc builder/listener not firing).

If I emit the changes with some delays using Future.delayed, it works.

So to summarize:

In this case, I see all emits identified by the listener of a BlocConsumer, but not by the builder:

emit(state.copyWith(someStringValue: "aaa"));
emit(state.copyWith(inputWord: "bbb"));
emit(state.copyWith(inputWord: "ccc"));

But it I delay the emits it is showing in both the listener and builder:

await Future.delayed(Duration(milliseconds: 100), () {
 emit(state.copyWith(someStringValue: "aaa"));
});

await Future.delayed(Duration(milliseconds: 300), () {
 emit(state.copyWith(inputWord: "bbb"));
});

await Future.delayed(Duration(milliseconds: 500), () {
 emit(state.copyWith(inputWord: "ccc"));
});

Is this the expected behavior? I suspect it's a gap in my understanding of how blocbuilder works.

0 Answers
Related