Bloc: State not rebuilding.

Created on 20 May 2020  路  7Comments  路  Source: felangel/bloc

Everything works fine in the starting but QuestionWidget has a button that triggers the GetQuestion event but the QestionWidget is not rebuilt. Or am I doing something wrong here?? I also tried removing equatable.

Widget build(BuildContext context) {
return Scaffold(
body: MultiBlocListener(
listeners: [
BlocListener(
listener: (context, state) {
if (state is NoQuestions) {
_dbbloc.add(GetQuestions());
} else if (state is HasQuestions) {
_statusbloc.add(GetQuestion());
}
},
),
BlocListener(
listener: (context, state) {
if (state is Loaded) {
_statusbloc.add(SetQuestions(questionsToSet: state.questions));
}
},
),
],
child: BlocBuilder(
builder: (context, state) {
if (state is QuestionLoaded) {
return QuestionWidget(question: state.question);
} else {
return CircularProgressIndicator();
}
},
),
),
);
}
}

This is what I get after clicking the button but the widget is not rebuilt.

I/flutter (26863): Instance of 'GetQuestion'
I/flutter (26863): Transition { currentState: Instance of 'QuestionLoaded', event: Instance of 'GetQuestion', nextState: Instance of 'QuestionLoaded' }

All 7 comments

Hi @CoderAssets 馃憢

What exactly do you mean by the widget is not rebuilt ? builder is not executed or the value of question inside QuestionWidget doesn't change ?

My plan is to rebuild entire QuestionWidget but no visible changes. I guess builder is not exeuted.

@CoderAssets can you share a gist or a repo with your issue ?

Not using equatable. Is there a chance that the build may not have happened because I was passing the same question. I just realized that the question was the same as the previous one.

That's precisely why I asked you regarding builder or widget value.

Glad you found the problem 馃憤

Thanks for your help.

Was this page helpful?
0 / 5 - 0 ratings