My StreamBuilder in view:
Widget build(BuildContext context) {
print("rebuilding..."); // as of now this gets called only on view initialization and never again - i.e. not on new events going through alarmController.stream
return StreamBuilder(
stream: widget.bloc.alarmController.stream,
initialData: Alarm(''),
builder: (BuildContext context, AsyncSnapshot<Alarm> snapshot) {
if (!snapshot.hasData) {
return Center(
child: Text(StringLiterals.NO_ALARM_DATA_MSG))
);
}
return Switch(
activeColor: Colors.red,
value: snapshot.data.status == 'Started',
onChanged: (bool _value) {
_newAlarmValue = _value;
_askAlarmConfirmation();
}));
});
}
meat of my bloc:
AlarmBloc(this.Api) {
getAlarm();
}
getAlarm() async {
Alarm response = await Api.getAlarmStatus();
alarmController.sink.add(response); // here im adding new event, therefore streambuilder should rebuild, right?
}
And lastly the code I call to initiate new event(in this case it's firebase message):
if(_message.notification.body.contains("Alarm") && IS_LOGGED_IN == true) {
alarmBloc.getAlarm();
}
So the problem is StreamBuilder not rebuilding whenever new event passes through alarmController.stream. What could be the reason?
StreamBuilder
. AFAIK it doesn't force the entire widget to rebuild. – Rafaelle