logout method Null safety

Future<void> logout()

Implementation

Future<void> logout() async {
  logger.i('logout');

  if (state.reconnecting) {
    eventManager.notifyReconnectionCanceled();
  }

  _sessionManager = SessionManager();
  _cache = MemoryCacheStorage();
  _cmdManager = CommandManager();
  _streamManager.reset();

  _commandQueue.cleanUp();
  _messageQueues.forEach((key, q) => q.cleanUp());
  _messageQueues = {};
  // _uploads.forEach((key, value) => _api.cancelUploadingFile(key));
  _uploads = {};

  // if previously existed completer with different userId then cancel out
  _loginCompleter?.completeError(ConnectionCancelError());
  _loginCompleter = null;

  // _api = ApiClient();
  // _api.initialize(appId: _state.appId);

  _state.cleanUp();
  logger.i('Deleting previous websocket');
  await _webSocket?.close();
  _webSocket = null;

  _ambiguate(WidgetsBinding.instance)?.removeObserver(this);
  registered = false;
  _connectionSub?.cancel();

  ConnectionManager.flushCompleters(error: ConnectionClosedError());
}