whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. List<String> tags,
    2. String? summary,
    3. String? description,
    4. String? operationId,
    5. List<Parameter> parameters,
    6. RequestBody? requestBody,
    7. Map<String, Response> responses,
    8. List<SecurityRequirement> security,
    9. List<String>? consumes,
    10. List<String>? produces,
    11. bool? deprecated,
    )?
)

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( List<String> tags,  String? summary,  String? description,  String? operationId,  List<Parameter> parameters,  RequestBody? requestBody,  Map<String, Response> responses,  List<SecurityRequirement> security,  List<String>? consumes,  List<String>? produces,  bool? deprecated)?  $default,) {final _that = this;
switch (_that) {
case _Operation() when $default != null:
return $default(_that.tags,_that.summary,_that.description,_that.operationId,_that.parameters,_that.requestBody,_that.responses,_that.security,_that.consumes,_that.produces,_that.deprecated);case _:
  return null;

}
}