felangel / bloc

A predictable state management library that helps implement the BLoC design pattern
https://bloclibrary.dev
MIT License
11.84k stars 3.4k forks source link

BlocBuilder only build once and stop rebuild with subsequent emit #4037

Closed TENX-S closed 10 months ago

TENX-S commented 10 months ago

I have an IconButton that click on it will pin/unpin the window, and the icon will change according to pinned or not. The first click on the button will trigger a rebuild event, but subsequent click does not. And I have absolutely no idea on it.

I created a minimal example here: https://gist.github.com/TENX-S/7a811cb23b3b0ed220b75f4b2cda7fd3, for repo: https://github.com/TENX-S/miniexample

I tried to read documentation on https://bloclibrary.dev/, but I'm not getting the answer to it.

Screen Recording 2024-01-08 at 10 39 18

Extra info:

Flutter 3.18.0-18.0.pre.25 • channel master •
https://github.com/flutter/flutter.git
Framework • revision 02d1d64e7f (2 weeks ago) • 2023-12-23 10:02:06 -0500
Engine • revision 8b839eda79
Tools • Dart 3.3.0 (build 3.3.0-260.0.dev) • DevTools 2.31.0-dev.0
codesculpture commented 10 months ago

Can u provide the output of the logs, build $alwaysonTop with screen recording @TENX-S

TENX-S commented 10 months ago

Yes @codesculpture

https://github.com/felangel/bloc/assets/40336192/5edd8c51-dc1d-422b-9e91-eb92aa8b47ea

codesculpture commented 10 months ago

Seems u made a hot-restart, can u share the log without doing it

TENX-S commented 10 months ago

If you do not hot-restart, there's only one log no matter how many times you click that button:

flutter: build true
TENX-S commented 10 months ago

FWIW, here's the video without hot-restart:

https://github.com/felangel/bloc/assets/40336192/d156f2c6-8797-4eac-8e1c-9dd6689c7c35

TENX-S commented 10 months ago

So it turns out there is something wrong with understanding; I shouldn't mutate the state but instead, I need to create a new one for emitting. (I learned this from somewhere else)

Sorry for the noise!