when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult assistantEnd(
    1. String? customSessionId
    ),
  2. required TResult assistantMessage(
    1. bool fromText,
    2. Message message,
    3. Models models,
    4. String? customSessionId,
    5. String? id,
    ),
  3. required TResult assistantProsody(
    1. Models models,
    2. String? customSessionId,
    3. String? id
    ),
  4. required TResult audioOutput(
    1. String data,
    2. String id,
    3. int index,
    4. String? customSessionId,
    ),
  5. required TResult chatMetadata(
    1. String chatGroupId,
    2. String chatId,
    3. String? requestId,
    4. String? customSessionId,
    ),
  6. required TResult error(
    1. String code,
    2. String message,
    3. String slug,
    4. String? customSessionId,
    5. String? requestId,
    ),
  7. required TResult userInterruption(
    1. int time,
    2. String? customSessionId
    ),
  8. required TResult userMessage(
    1. bool fromText,
    2. bool interim,
    3. Message message,
    4. Models models,
    5. TimeRange time,
    6. String? customSessionId,
    ),
  9. required TResult toolCall(
    1. String name,
    2. String parameters,
    3. bool responseRequired,
    4. String toolCallId,
    5. String? customSessionId,
    6. String? toolType,
    ),
  10. required TResult toolResponse(
    1. String content,
    2. String toolCallId,
    3. String? customSessionId,
    4. String? toolName,
    5. String? toolType,
    ),
  11. required TResult toolError(
    1. String error,
    2. String toolCallId,
    3. String? code,
    4. String? content,
    5. String? customSessionId,
    6. String? level,
    7. String? toolType,
    ),
})

A switch-like method, using callbacks.

As opposed to map, this offers destructuring. It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case Subclass2(:final field2):
    return ...;
}

Implementation

@optionalTypeArgs TResult when<TResult extends Object?>({required TResult Function( String? customSessionId)  assistantEnd,required TResult Function( bool fromText,  Message message,  Models models,  String? customSessionId,  String? id)  assistantMessage,required TResult Function( Models models,  String? customSessionId,  String? id)  assistantProsody,required TResult Function( String data,  String id,  int index,  String? customSessionId)  audioOutput,required TResult Function( String chatGroupId,  String chatId,  String? requestId,  String? customSessionId)  chatMetadata,required TResult Function( String code,  String message,  String slug,  String? customSessionId,  String? requestId)  error,required TResult Function( int time,  String? customSessionId)  userInterruption,required TResult Function( bool fromText,  bool interim,  Message message,  Models models,  TimeRange time,  String? customSessionId)  userMessage,required TResult Function( String name,  String parameters,  bool responseRequired,  String toolCallId,  String? customSessionId,  String? toolType)  toolCall,required TResult Function( String content,  String toolCallId,  String? customSessionId,  String? toolName,  String? toolType)  toolResponse,required TResult Function( String error,  String toolCallId,  String? code,  String? content,  String? customSessionId,  String? level,  String? toolType)  toolError,}) {final _that = this;
switch (_that) {
case AssistantEnd():
return assistantEnd(_that.customSessionId);case AssistantMessage():
return assistantMessage(_that.fromText,_that.message,_that.models,_that.customSessionId,_that.id);case AssistantProsody():
return assistantProsody(_that.models,_that.customSessionId,_that.id);case AudioOutput():
return audioOutput(_that.data,_that.id,_that.index,_that.customSessionId);case ChatMetadata():
return chatMetadata(_that.chatGroupId,_that.chatId,_that.requestId,_that.customSessionId);case ReceiveMessageError():
return error(_that.code,_that.message,_that.slug,_that.customSessionId,_that.requestId);case UserInterruption():
return userInterruption(_that.time,_that.customSessionId);case UserMessage():
return userMessage(_that.fromText,_that.interim,_that.message,_that.models,_that.time,_that.customSessionId);case ToolCallMessage():
return toolCall(_that.name,_that.parameters,_that.responseRequired,_that.toolCallId,_that.customSessionId,_that.toolType);case ToolResponseMessage():
return toolResponse(_that.content,_that.toolCallId,_that.customSessionId,_that.toolName,_that.toolType);case ToolErrorMessage():
return toolError(_that.error,_that.toolCallId,_that.code,_that.content,_that.customSessionId,_that.level,_that.toolType);}
}