when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- int userId,
- Sub2ApiDecimal todayActualCost,
- Sub2ApiDecimal totalActualCost,
- List<
Sub2ApiAdminPlatformUsage> ? byPlatform,
A switch-like method, using callbacks.
As opposed to map, this offers destructuring.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case Subclass2(:final field2):
return ...;
}
Implementation
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function(
int userId,
Sub2ApiDecimal todayActualCost,
Sub2ApiDecimal totalActualCost,
List<Sub2ApiAdminPlatformUsage>? byPlatform,
)
$default,
) {
final _that = this;
switch (_that) {
case _Sub2ApiAdminBatchUserUsageStats():
return $default(
_that.userId,
_that.todayActualCost,
_that.totalActualCost,
_that.byPlatform,
);
case _:
throw StateError('Unexpected subclass');
}
}