Basically, I'm trying to check the status of my WebSocket Server.ws . However, when I query Server.ws.readyState , the only response I ever get is WebSocket.OPEN . How do I check if a WebSocket is disconnected if it always returns WebSocket.OPEN ?

For example, I've tried to turn off the WiFi of the device used to test the Flutter app. Normally, after one second, the WebSocket is assumed disconnected and the connection is closed with a WebSocketStatus.GOING_AWAY close code. I assumed it would also change the WebSocket.readyState , but that doesn't seems to be the case.

So, how do I properly check the status of my WebSocket?

How I'm currently checking :

/// Connection status IconButton _status() { IconData iconData; switch (Server.ws?.readyState) { case WebSocket.CONNECTING: print("readyState : CONNECTING"); iconData = Icons.wifi; break; case WebSocket.OPEN: print("readyState : OPEN"); iconData = Icons.signal_wifi_4_bar; break; case WebSocket.CLOSING: print("readyState : CLOSING"); iconData = Icons.signal_wifi_4_bar_lock; break; case WebSocket.CLOSED: print("readyState : CLOSED"); iconData = Icons.warning; break; default: print("readyState : " + Server.ws.readyState.toString()); break; } return new IconButton( icon: new Icon(iconData), tooltip: 'Connection Status', // TODO:Localize onPressed: () { setState(() { Server.ws.close(); }); }, ); }

Additional info about the WebSocket :