Bài đăng

Đang hiển thị bài đăng từ Tháng 3, 2023

[Flutter]-Single stream vs broadcast stream

Single   stream and a broadcast stream may seem very similar, as both examples use a StreamController to emit values and a StreamBuilder widget to listen to the stream and update the UI. The main difference between a single stream and a broadcast stream is not in the way we create or use the StreamController, but in how the stream is listened to by listeners. In the case of a single stream, only one listener can be actively subscribed to the stream at any given time, while in the case of a broadcast stream, multiple listeners can be subscribed to the stream at the same time. Here's an example that demonstrates the difference more clearly: Let's say we want to create an app that displays a live feed of a chat room. Using a single stream, we can have only one user listening to the chat room feed at a time, which means that only one user will be able to see the messages that are sent. On the other hand, if we use a broadcast stream, we can have multiple users listening to the chat...