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