whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<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 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 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() when $default != null:
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 _:
  return null;

}
}