whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. DateTime? startDate,
    2. DateTime? endDate,
    3. String? timezone,
    4. int? groupId,
    5. String? model,
    6. Sub2ApiAdminModelSource modelSource,
    7. String? endpoint,
    8. Sub2ApiAdminEndpointType endpointType,
    9. int? userId,
    10. int? apiKeyId,
    11. int? accountId,
    12. Sub2ApiAdminUsageRequestType? requestType,
    13. bool? stream,
    14. Sub2ApiAdminBillingType? billingType,
    15. Sub2ApiAdminUserBreakdownSort? sortBy,
    16. int limit,
    )?
)

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(
    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() when $default != null:
      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 _:
      return null;
  }
}