whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? $default(
- int userId,
- String email,
- int requests,
- int inputTokens,
- int outputTokens,
- int cacheTokens,
- int totalTokens,
- Sub2ApiDecimal cost,
- Sub2ApiDecimal actualCost,
- Sub2ApiDecimal accountCost,
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(
int userId,
String email,
int requests,
int inputTokens,
int outputTokens,
int cacheTokens,
int totalTokens,
Sub2ApiDecimal cost,
Sub2ApiDecimal actualCost,
Sub2ApiDecimal accountCost,
)?
$default,
) {
final _that = this;
switch (_that) {
case _Sub2ApiAdminUserBreakdownItem() when $default != null:
return $default(
_that.userId,
_that.email,
_that.requests,
_that.inputTokens,
_that.outputTokens,
_that.cacheTokens,
_that.totalTokens,
_that.cost,
_that.actualCost,
_that.accountCost,
);
case _:
return null;
}
}