when<TResult extends Object?> method
- @optionalTypeArgs
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( String title, String version, String? description, String? termsOfService, Contact? contact, License? license, String? summary, @JsonKey(includeIfNull: false, includeFromJson: false, includeToJson: false) Map<String, dynamic>? extensions) $default,) {final _that = this;
switch (_that) {
case _Info():
return $default(_that.title,_that.version,_that.description,_that.termsOfService,_that.contact,_that.license,_that.summary,_that.extensions);case _:
throw StateError('Unexpected subclass');
}
}