when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult postView(
    1. PostView data
    ),
  2. required TResult notFoundPost(
    1. NotFoundPost data
    ),
  3. required TResult blockedPost(
    1. BlockedPost data
    ),
  4. required TResult unknown(
    1. Map<String, dynamic> data
    ),
})

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);}
}