whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>(
- TResult? $default(
- String id,
- String? name,
- String? resourceType,
- String? resourceId,
- String? userId,
- String? agentId,
- String? errorMessage,
- String? errorCode,
- int? pullRequestNumber,
- String? pullRequestUrl,
- String? pullRequestId,
- String? pullRequestBaseRef,
- GithubCopilotSessionStatus status,
- ModelTimestamp? completedAt,
- ModelTimestamp createdAt,
- ModelTimestamp updatedAt,
- bool fromServer,
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 id,
String? name,
String? resourceType,
String? resourceId,
String? userId,
String? agentId,
String? errorMessage,
String? errorCode,
int? pullRequestNumber,
String? pullRequestUrl,
String? pullRequestId,
String? pullRequestBaseRef,
GithubCopilotSessionStatus status,
ModelTimestamp? completedAt,
ModelTimestamp createdAt,
ModelTimestamp updatedAt,
bool fromServer)?
$default,
) {
final _that = this;
switch (_that) {
case _GithubCopilotSessionModel() when $default != null:
return $default(
_that.id,
_that.name,
_that.resourceType,
_that.resourceId,
_that.userId,
_that.agentId,
_that.errorMessage,
_that.errorCode,
_that.pullRequestNumber,
_that.pullRequestUrl,
_that.pullRequestId,
_that.pullRequestBaseRef,
_that.status,
_that.completedAt,
_that.createdAt,
_that.updatedAt,
_that.fromServer);
case _:
return null;
}
}