when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult assistantEnd(
- String? customSessionId
- required TResult assistantMessage(),
- required TResult assistantProsody(),
- required TResult audioOutput(),
- required TResult chatMetadata(),
- required TResult error(),
- required TResult userInterruption(),
- required TResult userMessage(),
- required TResult toolCall(),
- required TResult toolResponse(),
- required TResult toolError(),
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);}
}