when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String key,
    2. String title,
    3. String? publishDate,
    4. List<String>? publishers,
    5. int? numberOfPages,
    6. List<int>? covers,
    7. List<AuthorKey> authors,
    8. List<String>? isbn10,
    9. List<String>? isbn13,
    )
)

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 key,  String title, @JsonKey(name: 'publish_date')  String? publishDate,  List<String>? publishers, @JsonKey(name: 'number_of_pages')  int? numberOfPages,  List<int>? covers,  List<AuthorKey> authors, @JsonKey(name: 'isbn_10')  List<String>? isbn10, @JsonKey(name: 'isbn_13')  List<String>? isbn13)  $default,) {final _that = this;
switch (_that) {
case _Book():
return $default(_that.key,_that.title,_that.publishDate,_that.publishers,_that.numberOfPages,_that.covers,_that.authors,_that.isbn10,_that.isbn13);case _:
  throw StateError('Unexpected subclass');

}
}