Hi @felangel is it the best practices to have multiple blocs for one page for each widget that we
only want to change ?
for example, if I have pages that have 3 widget:
widget A
widget B
widget C
only widget B and C (different state) that will be rebuild if there's some state changed.
should I create 2 different bloc for each widget B and C, and wrap them in it ? in this case it will be widgetABloc and widgetBBloc.
I personally doesn't want to rebuild widget A for there's no changes for it.
thank you.
If you feel you wanna optimize anything, do it.
Of course, if there is no caching of some kind, all the widgets inside BlocBuilder will be redrawn on state updates. They might be (and probably will be) also redrawn anytime Flutter feels like it. So I would not go to over-optimizing this, because it doesn't really come with any major benefit anyway. At least if you don't have thousands of widgets there, and at that point you probably using some ListView.builder or so anyway.
Hi @gabrielintang 馃憢
Thanks for opening an issue!
There are several things you can do depending on the situation:
BlocBuilder (only wrap the widgets that need to rebuild)BlocBuilder and add a condition to eachWith all that being said, please don't spend too much time trying to optimize for rebuilds unless you are having performance problems (as @tenhobi mentioned).
Hope that helps!
Closing for now but feel free to comment with additional questions and I'm happy to continue the conversation 馃憤
Most helpful comment
If you feel you wanna optimize anything, do it.
Of course, if there is no caching of some kind, all the widgets inside
BlocBuilderwill be redrawn on state updates. They might be (and probably will be) also redrawn anytime Flutter feels like it. So I would not go to over-optimizing this, because it doesn't really come with any major benefit anyway. At least if you don't have thousands of widgets there, and at that point you probably using someListView.builderor so anyway.