maybeWhen<TResult extends Object?> method
- @optionalTypeArgs
- TResult postView(
- PostView data
- TResult notFoundPost(
- NotFoundPost data
- TResult blockedPost(
- BlockedPost data
- TResult unknown()?,
- required TResult orElse(),
A variant of when
that fallback to an orElse
callback.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return orElse();
}
Implementation
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( PostView data)? postView,TResult Function( NotFoundPost data)? notFoundPost,TResult Function( BlockedPost data)? blockedPost,TResult Function( Map<String, dynamic> data)? unknown,required TResult orElse(),}) {final _that = this;
switch (_that) {
case UReplyRefRootPostView() when postView != null:
return postView(_that.data);case UReplyRefRootNotFoundPost() when notFoundPost != null:
return notFoundPost(_that.data);case UReplyRefRootBlockedPost() when blockedPost != null:
return blockedPost(_that.data);case UReplyRefRootUnknown() when unknown != null:
return unknown(_that.data);case _:
return orElse();
}
}