Flutter - WebSocketChannel listen method is not getting triggered

6 Views Asked by At

I am trying to parse bytes data using WebSocketChannel in flutter but after successful request in bytes, callback method of stream in not getting called. Here is sample code:

 /// connect
var connection = WebSocket.connect(socketUrl);
connection.then((ws) {
  _channel = IOWebSocketChannel(ws);
  if (_channel != null) {
    debugPrint("connecting");
    connectionListener.onConnected(_channel!);

    _channel?.stream.listen((event) {
      debugPrint("listen $event");
      }, onError: (error) {
      debugPrint("ERROR $error");
      connectionListener.onError(error);
    }, onDone: () {
      debugPrint("onDone-");
    });
  }
}).onError((error, stackTrace) {
   debugPrint("ERROR $error");

  connectionListener.onError(error.toString());
});
0

There are 0 best solutions below