whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. AuthorV2? author,
    2. List<Comment>? commentList,
    3. String? content,
    4. String? contentHtml,
    5. String? excerpt,
    6. String? excerptHtml,
    7. String? handle,
    8. String? id,
    9. ShopifyImage? image,
    10. String? publishedAt,
    11. List<String>? tags,
    12. String? title,
    13. String? onlineStoreUrl,
    )?
)

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( AuthorV2? author,  List<Comment>? commentList,  String? content,  String? contentHtml,  String? excerpt,  String? excerptHtml,  String? handle,  String? id,  ShopifyImage? image,  String? publishedAt,  List<String>? tags,  String? title,  String? onlineStoreUrl)?  $default,) {final _that = this;
switch (_that) {
case _Article() when $default != null:
return $default(_that.author,_that.commentList,_that.content,_that.contentHtml,_that.excerpt,_that.excerptHtml,_that.handle,_that.id,_that.image,_that.publishedAt,_that.tags,_that.title,_that.onlineStoreUrl);case _:
  return null;

}
}