when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult postView(
- PostView data
- required TResult notFoundPost(
- NotFoundPost data
- required TResult blockedPost(
- BlockedPost data
- required TResult 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?>({required TResult Function( PostView data) postView,required TResult Function( NotFoundPost data) notFoundPost,required TResult Function( BlockedPost data) blockedPost,required TResult Function( Map<String, dynamic> data) unknown,}) {final _that = this;
switch (_that) {
case UReplyRefParentPostView():
return postView(_that.data);case UReplyRefParentNotFoundPost():
return notFoundPost(_that.data);case UReplyRefParentBlockedPost():
return blockedPost(_that.data);case UReplyRefParentUnknown():
return unknown(_that.data);}
}