I'm using Flutter (BloC pattern) to build a widget that streams multiple camera feeds. When a feed is clicked on, it is shown in the main feed (think Google hangouts, where the face of whoever is speaking is shown front and centre, and others are smaller at the side).
When trying to switch the selected feed, the state (int
) gets yielded with the expected new value by the Bloc
's MapEventToState
; however, the main CamFeed
widget doesn't switch feeds.
My understanding of this usage of a StatefulWidget
that returns a BlocBuilder<CamSwitcherBloc, int>
should rebuild when that int is changed. Instead, nothing seems to be happening. build()
is only getting called when it first gets created, and when the state of one of the children within CamFeed
is getting updated.
I've confirmed via observatory that there is, as expected, only one instance of the CamSwitcherBloc
.
So - am I wrong in thinking that:
When MapEventToState inside my Bloc yields a new value (selectedCam, type in the builder below), build()
should be called for my widget.
If that is correct, any suggestions as to where to continue my hunt would be greatly appreciated.
Thanks!
class CamSwitcher extends StatefulWidget {
@override
_CamSwitcherState createState() => _CamSwitcherState();
}
class _CamSwitcherState extends State<CamSwitcher> {
@override
Widget build(BuildContext context) {
final camSwitcherBloc = BlocProvider.of<CamSwitcherBloc>(context);
return BlocBuilder<CamSwitcherBloc, int>(
builder: (context, selectedCam) => Stack(
children: <Widget>[
Container(
width: 1200,
height: 800,
child: CamFeed(
topic: camSwitcherBloc.cameras[selectedCam],
),
),
Row(
children: <Widget>[
Container(
width: 180,
height: 120,
child: CamFeed(
topic: CamSwitcherBloc.cam1,
focuser: () {
camSwitcherBloc.dispatch(ExpandCamera(0));
},
),
),
Container(
width: 180,
height: 120,
child: CamFeed(
topic: CamSwitcherBloc.cam2,
focuser: () {
camSwitcherBloc.dispatch(ExpandCamera(1));
},
),
),
],
),
],
),
);
}
}