when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String $type,
- AtUri uri,
- String cid,
- ProfileViewBasic author,
- Map<
String, dynamic> record, - UPostViewEmbed? embed,
- int? bookmarkCount,
- int? replyCount,
- int? repostCount,
- int? likeCount,
- int? quoteCount,
- DateTime indexedAt,
- ViewerState? viewer,
- List<
Label> ? labels, - ThreadgateView? threadgate,
- Map<
String, dynamic> ? $unknown,
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 $type, @AtUriConverter() AtUri uri, String cid, @ProfileViewBasicConverter() ProfileViewBasic author, Map<String, dynamic> record, @UPostViewEmbedConverter() UPostViewEmbed? embed, int? bookmarkCount, int? replyCount, int? repostCount, int? likeCount, int? quoteCount, DateTime indexedAt, @ViewerStateConverter() ViewerState? viewer, @LabelConverter() List<Label>? labels, @ThreadgateViewConverter() ThreadgateView? threadgate, Map<String, dynamic>? $unknown) $default,) {final _that = this;
switch (_that) {
case _PostView():
return $default(_that.$type,_that.uri,_that.cid,_that.author,_that.record,_that.embed,_that.bookmarkCount,_that.replyCount,_that.repostCount,_that.likeCount,_that.quoteCount,_that.indexedAt,_that.viewer,_that.labels,_that.threadgate,_that.$unknown);case _:
throw StateError('Unexpected subclass');
}
}