The WebSocketChannel provides a
Stream of messages from the server.

The Stream class is a fundamental part of the dart:async package.
It provides a way to listen to async events from a data source.
Unlike Future, which returns a single async response,
the Stream class can deliver many events over time.

The StreamBuilder widget connects to a Stream
and asks Flutter to rebuild every time it
receives an event using the given builder() function.

3. Send data to the server

To send data to the server,
add() messages to the sink provided
by the WebSocketChannel.

How this works

The WebSocketChannel provides a
StreamSink to push messages to the server.

The StreamSink class provides a general way to add sync or async
events to a data source.

4. Close the WebSocket connection

After you’re done using the WebSocket, close the connection:

Complete example