How can I listen to stream and emit state with Cubit
?
With Bloc
we can do something like this:
on<VideoStreamPlayPauseEvent>(
(event, emit) async {
if (event.play) {
await emit.forEach(
videoStreamingRepo.videoDataStream,
onData: (VideoData videoStreamData) => VideoStreamState(
currentFrame: videoStreamData,
isPlaying: true,
),
);
}
2
Answers
My final result is
You should listen to the
stream
usinglisten()
and based on the
event
you canemit
the desired state.Extra: Based on the demand of questioner
To Stop listening to stream: