在 BlocConsumer 中使用 BlocBuilder 并将对应的 state 传递到 BlocListener 中,来实现对特定状态的侦听。
以下是代码示例:
BlocBuilder(
builder: (context, state) {
return BlocListener(
listener: (context, state) {
if (state is MySpecialState) {
// Do something special
}
},
child: // Child widget tree,
bloc: myBloc,
);
},
bloc: myBloc,
);
上一篇:BlocConsumer小部件的子BlocBuilder小部件没有传递状态?
下一篇:bloccubitflutter出现“TypeError:Cannotreadpropertiesofnull(reading'getAllPostsRep')”