whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? assistantEnd(
- String? customSessionId
- TResult? assistantMessage()?,
- TResult? assistantProsody()?,
- TResult? audioOutput()?,
- TResult? chatMetadata()?,
- TResult? error()?,
- TResult? userInterruption()?,
- TResult? userMessage()?,
- TResult? toolCall()?,
- TResult? toolResponse()?,
- TResult? toolError()?,
A variant of when that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>({TResult? Function( String? customSessionId)? assistantEnd,TResult? Function( bool fromText, Message message, Models models, String? customSessionId, String? id)? assistantMessage,TResult? Function( Models models, String? customSessionId, String? id)? assistantProsody,TResult? Function( String data, String id, int index, String? customSessionId)? audioOutput,TResult? Function( String chatGroupId, String chatId, String? requestId, String? customSessionId)? chatMetadata,TResult? Function( String code, String message, String slug, String? customSessionId, String? requestId)? error,TResult? Function( int time, String? customSessionId)? userInterruption,TResult? Function( bool fromText, bool interim, Message message, Models models, TimeRange time, String? customSessionId)? userMessage,TResult? Function( String name, String parameters, bool responseRequired, String toolCallId, String? customSessionId, String? toolType)? toolCall,TResult? Function( String content, String toolCallId, String? customSessionId, String? toolName, String? toolType)? toolResponse,TResult? Function( String error, String toolCallId, String? code, String? content, String? customSessionId, String? level, String? toolType)? toolError,}) {final _that = this;
switch (_that) {
case AssistantEnd() when assistantEnd != null:
return assistantEnd(_that.customSessionId);case AssistantMessage() when assistantMessage != null:
return assistantMessage(_that.fromText,_that.message,_that.models,_that.customSessionId,_that.id);case AssistantProsody() when assistantProsody != null:
return assistantProsody(_that.models,_that.customSessionId,_that.id);case AudioOutput() when audioOutput != null:
return audioOutput(_that.data,_that.id,_that.index,_that.customSessionId);case ChatMetadata() when chatMetadata != null:
return chatMetadata(_that.chatGroupId,_that.chatId,_that.requestId,_that.customSessionId);case ReceiveMessageError() when error != null:
return error(_that.code,_that.message,_that.slug,_that.customSessionId,_that.requestId);case UserInterruption() when userInterruption != null:
return userInterruption(_that.time,_that.customSessionId);case UserMessage() when userMessage != null:
return userMessage(_that.fromText,_that.interim,_that.message,_that.models,_that.time,_that.customSessionId);case ToolCallMessage() when toolCall != null:
return toolCall(_that.name,_that.parameters,_that.responseRequired,_that.toolCallId,_that.customSessionId,_that.toolType);case ToolResponseMessage() when toolResponse != null:
return toolResponse(_that.content,_that.toolCallId,_that.customSessionId,_that.toolName,_that.toolType);case ToolErrorMessage() when toolError != null:
return toolError(_that.error,_that.toolCallId,_that.code,_that.content,_that.customSessionId,_that.level,_that.toolType);case _:
return null;
}
}