when<TResult extends Object?> method
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 id, String name, String? url, @JsonKey(name: 'image_path') String? imagePath, String? details, int? rating100, @JsonKey(name: 'scene_count') int sceneCount, @JsonKey(name: 'image_count') int imageCount, @JsonKey(name: 'gallery_count') int galleryCount, @JsonKey(name: 'performer_count') int performerCount, bool favorite) $default,) {final _that = this;
switch (_that) {
case _Studio():
return $default(_that.id,_that.name,_that.url,_that.imagePath,_that.details,_that.rating100,_that.sceneCount,_that.imageCount,_that.galleryCount,_that.performerCount,_that.favorite);case _:
throw StateError('Unexpected subclass');
}
}