stream method
Retrieves a list stream of chat messages that already exist in the room.
the stream will dynamically update when new chat messages are received,
and you can use a StreamBuilder
to listen to it and update the UI in real time.
@return A List
of ZegoInRoomMessage objects representing the chat messages that
already exist in the room.
Example:
..foreground = Positioned(
left: 10,
bottom: 50,
child: StreamBuilder<List<ZegoInRoomMessage>>(
stream: liveController.message.stream(),
builder: (context, snapshot) {
final messages = snapshot.data ?? <ZegoInRoomMessage>[];
return Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
),
child: ListView.builder(
itemCount: messages.length,
itemBuilder: (context, index) {
final message = messages[index];
return Text('${message.user.name}: ${message.message}');
},
),
);
},
),
)
Implementation
Stream<List<ZegoInRoomMessage>> stream() {
return ZegoUIKit().getInRoomMessageListStream();
}