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