whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>()
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;
}
}