close method Null safety

Future<bool> close(
  1. {int code = WebSocketStatus.normalClosure,
  2. String reason = ''}
)

Implementation

Future<bool> close(
    {int code = WebSocketStatus.normalClosure, String reason = ''}) async {
  if (!_connected) {
    return true;
  }
  if (_socket == null) {
    return true;
  }

  //Prevent Re-Connect
  _disconnect = true;
  _connected = false;

  _stopPing();

  try {
    //This should trigger callback for Done()
    //And set _connected to false before returning from close
    await _socket?.sink.close(code, reason);
    _subscription?.cancel();
    _socket = null;
    logger.i('Socket closed ' + reason);
    return true;
  } catch (e) {
    onReceiveError(e);
    return false;
  }
}