Home:ALL Converter>How to implement websocket_channel with bloc in flutter

How to implement websocket_channel with bloc in flutter

Ask Time:2021-07-28T15:07:09         Author:Ye Lin Aung

Json Formatter

below is my websocket provider .it doesn't even hit to the server when I called from block builder

I can connect to the server without bloc, I tried a lot examples but failed I need help guys , thanks any example about flutter bloc with web_socket_channel WebSocket provider

      static final String wsRelationUrl = "ws://127.0.0.1:8080/chat/";
      final IOWebSocketChannel _channel =
          IOWebSocketChannel.connect(wsRelationUrl, headers: headers);
      WebSocketProvider();

      @override
      Future<void> disconect() async {
        if (_channel != null) {
          _channel.sink.close();
        }
      }

      @override
      Future<Stream> messages() async {
        if (_channel != null) {
          return _channel.stream;
        }
        return null;
      }

      @override
      Future<void> sendMessage(String message) async {
        if (_channel != null) {
          return _channel.sink.add(message);
        }
      }
    
    }
     

Author:Ye Lin Aung,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/68555878/how-to-implement-websocket-channel-with-bloc-in-flutter
yy