I have a problem with my stream. I have a StreamController.broadcast() active in the project which is used on 2 different screens. And I have a listen method on this Stream so when the value stored in it changes, the component will update with the new value. But, even with the listen, after being modified only once, the Stream doesn't work anymore (I can add values to it, but the component doesn't update anymore)
My Stream
StreamController<String> userProfilePhotoController = StreamController.broadcast();
The 'Listen' Method
This method is called in a initState method.
profilePhotoListen() {
controller.userProfilePhotoController.stream.listen(
(e) => setState(() {
//This is basically a 'print' function
Log.log(e, name: "AVATAR PATH");
}),
);
}
The Method that sets the value on the Stream
setProfileAvatar({required String path}) {
userProfilePhotoController.sink.add(path);
userProfilePhoto = path;
}
When the setProfileAvatar({required String path}) is called for the first time, the Stream receive the value and my component update without a problem. But when the method is called a second time, the Stream receive the value, but the component doesn't update.
The Component
StreamBuilder<String>(
stream: controller.userProfilePhotoController.stream,
builder: (context, snapshot) {
if (snapshot.hasData && snapshot.data != null) {
return RegisterAvatar(
path: snapshot.data!,
onTap: () => Modular.to.pushNamed(
'.$kRouteRegisterProfilePicture'),
);
}
return RegisterAvatarPlaceholder(
onTap: () => Modular.to
.pushNamed('.$kRouteRegisterProfilePicture'),
);
},
),