BlocBuilder
of flutter_bloc
is kind of put all state of page together.
There's a case for pulling a list
there's 2 data (isPullingState
, dataList
), how can I avoid build widget part of dataList when dataList
not change, but build widget part of isPullingState
which changed from true to false ?
BlocBuilderCondition
looks like only avoid rebuild when hole state not change.
The
BlocBuilder
have a optinal parametercondition
that have typebool Function(State previous, State current)
, you need to returntrue
if you want the widget call thebuilder
function, andfalse
if you don't want. This parameter is optional, and by default istrue
.Because the in the
condition
parameter you have theprevious
state and thecurrent
state you can compare the properties of this states and and returntrue
if it satisfies your comparisons.Remember that you need to override the
==
operator andhashCode
of your state and all classes that use in your state class. And easy way to do this is using equatable.In your case you need to have a
State
like this:And then in your widget you can set the condition that you want: