when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- DateTime? startDate,
- DateTime? endDate,
- String? timezone,
- int? groupId,
- String? model,
- Sub2ApiAdminModelSource modelSource,
- String? endpoint,
- Sub2ApiAdminEndpointType endpointType,
- int? userId,
- int? apiKeyId,
- int? accountId,
- Sub2ApiAdminUsageRequestType? requestType,
- bool? stream,
- Sub2ApiAdminBillingType? billingType,
- Sub2ApiAdminUserBreakdownSort? sortBy,
- int limit,
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(
DateTime? startDate,
DateTime? endDate,
String? timezone,
int? groupId,
String? model,
Sub2ApiAdminModelSource modelSource,
String? endpoint,
Sub2ApiAdminEndpointType endpointType,
int? userId,
int? apiKeyId,
int? accountId,
Sub2ApiAdminUsageRequestType? requestType,
bool? stream,
Sub2ApiAdminBillingType? billingType,
Sub2ApiAdminUserBreakdownSort? sortBy,
int limit,
)
$default,
) {
final _that = this;
switch (_that) {
case _Sub2ApiAdminUserBreakdownQuery():
return $default(
_that.startDate,
_that.endDate,
_that.timezone,
_that.groupId,
_that.model,
_that.modelSource,
_that.endpoint,
_that.endpointType,
_that.userId,
_that.apiKeyId,
_that.accountId,
_that.requestType,
_that.stream,
_that.billingType,
_that.sortBy,
_that.limit,
);
case _:
throw StateError('Unexpected subclass');
}
}