whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String title,
    2. String version,
    3. @JsonKey.new(includeIfNull: false) String? description,
    4. @JsonKey.new(includeIfNull: false) String? termsOfService,
    5. @JsonKey.new(includeIfNull: false) Contact? contact,
    6. @JsonKey.new(includeIfNull: false) License? license,
    7. @JsonKey.new(includeIfNull: false) String? summary,
    8. @JsonKey.new(includeIfNull: false, includeFromJson: false, includeToJson: false) Map<String, dynamic>? extensions,
    )?
)

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 title,  String version, @JsonKey(includeIfNull: false)  String? description, @JsonKey(includeIfNull: false)  String? termsOfService, @JsonKey(includeIfNull: false)  Contact? contact, @JsonKey(includeIfNull: false)  License? license, @JsonKey(includeIfNull: false)  String? summary, @JsonKey(includeIfNull: false, includeFromJson: false, includeToJson: false)  Map<String, dynamic>? extensions)?  $default,) {final _that = this;
switch (_that) {
case _Info() when $default != null:
return $default(_that.title,_that.version,_that.description,_that.termsOfService,_that.contact,_that.license,_that.summary,_that.extensions);case _:
  return null;

}
}