leave method Null safety

Push leave(
  1. {Duration? timeout}
)

Leave this channel.

Implementation

Push leave({Duration? timeout}) {
  _joinPush.cancelTimeout();
  _rejoinTimer?.cancel();

  final prevState = _state;
  _state = PhoenixChannelState.leaving;

  final leavePush = Push(
    this,
    event: PhoenixChannelEvent.leave,
    payload: () => {},
    timeout: timeout ?? _timeout,
  );

  if (!socket.isConnected || prevState != PhoenixChannelState.joined) {
    leavePush.trigger(PushResponse(status: 'ok'));
  } else {
    final onClose = (PushResponse reply) {
      _onClose(reply);
      close();
    };
    leavePush
      ..onReply('ok', onClose)
      ..onReply('timeout', onClose)
      ..send();
  }

  return leavePush;
}