map<T> method

T map<T>({
  1. required T onDisconnected(),
  2. required T onConnecting(),
  3. required T onConnected(
    1. ServerInfo serverInfo
    ),
  4. required T onDisconnecting(),
  5. required T onError(
    1. Object error,
    2. StackTrace? stackTrace
    ),
})

Maps the state to a value using the provided functions

Implementation

T map<T>({
  required T Function() onDisconnected,
  required T Function() onConnecting,
  required T Function(ServerInfo serverInfo) onConnected,
  required T Function() onDisconnecting,
  required T Function(Object error, StackTrace? stackTrace) onError,
}) => switch (this) {
  Disconnected() => onDisconnected(),
  Connecting() => onConnecting(),
  Connected(serverInfo: final info) => onConnected(info),
  Disconnecting() => onDisconnecting(),
  ConnectionError(error: final error, stackTrace: final stackTrace) =>
    onError(error, stackTrace),
};