maybeWhen<TResult extends Object?> method

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

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeWhen<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,required TResult orElse(),}) {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 orElse();

}
}