when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String name,
    3. String? url,
    4. String? imagePath,
    5. String? details,
    6. int? rating100,
    7. int sceneCount,
    8. int imageCount,
    9. int galleryCount,
    10. int performerCount,
    11. bool favorite,
    )
)

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');

}
}