maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
  1. TResult audioInput(
    1. String data,
    2. String? customSessionId
    )?,
  2. TResult sessionSettings(
    1. AudioSettings? audio,
    2. List<BuiltinTool>? builtinTools,
    3. ContextSettings? context,
    4. String? customSessionId,
    5. String? languageModelApiKey,
    6. Map<String, dynamic>? metadata,
    7. String? systemPrompt,
    8. List<UserDefinedTool>? tools,
    9. Map<String, dynamic>? variables,
    10. String? voiceId,
    )?,
  3. TResult userInput(
    1. String data,
    2. String? customSessionId
    )?,
  4. TResult assistantInput(
    1. String data,
    2. String? customSessionId
    )?,
  5. TResult toolResponse(
    1. String content,
    2. String toolCallId,
    3. String? customSessionId,
    4. String? toolName,
    5. String? toolType,
    )?,
  6. TResult toolError(
    1. String error,
    2. String toolCallId,
    3. String? code,
    4. String? content,
    5. String? customSessionId,
    6. String? level,
    7. String? toolType,
    )?,
  7. TResult pauseAssistantMessage(
    1. String? customSessionId
    )?,
  8. TResult resumeAssistantMessage(
    1. String? customSessionId
    )?,
  9. 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 data,  String? customSessionId)?  audioInput,TResult Function( AudioSettings? audio,  List<BuiltinTool>? builtinTools,  ContextSettings? context,  String? customSessionId,  String? languageModelApiKey,  Map<String, dynamic>? metadata,  String? systemPrompt,  List<UserDefinedTool>? tools,  Map<String, dynamic>? variables,  String? voiceId)?  sessionSettings,TResult Function( String text,  String? customSessionId)?  userInput,TResult Function( String text,  String? customSessionId)?  assistantInput,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,TResult Function( String? customSessionId)?  pauseAssistantMessage,TResult Function( String? customSessionId)?  resumeAssistantMessage,required TResult orElse(),}) {final _that = this;
switch (_that) {
case AudioInput() when audioInput != null:
return audioInput(_that.data,_that.customSessionId);case SessionSettings() when sessionSettings != null:
return sessionSettings(_that.audio,_that.builtinTools,_that.context,_that.customSessionId,_that.languageModelApiKey,_that.metadata,_that.systemPrompt,_that.tools,_that.variables,_that.voiceId);case UserInput() when userInput != null:
return userInput(_that.text,_that.customSessionId);case AssistantInput() when assistantInput != null:
return assistantInput(_that.text,_that.customSessionId);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 PauseAssistantMessage() when pauseAssistantMessage != null:
return pauseAssistantMessage(_that.customSessionId);case ResumeAssistantMessage() when resumeAssistantMessage != null:
return resumeAssistantMessage(_that.customSessionId);case _:
  return orElse();

}
}