whenOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? profileViewBasic(
- ProfileViewBasic data
- TResult? profileView(
- ProfileView data
- TResult? profileViewDetailed(
- ProfileViewDetailed data
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( ProfileViewBasic data)? profileViewBasic,TResult? Function( ProfileView data)? profileView,TResult? Function( ProfileViewDetailed data)? profileViewDetailed,}) {final _that = this;
switch (_that) {
case UModerationSubjectProfileProfileViewBasic() when profileViewBasic != null:
return profileViewBasic(_that.data);case UModerationSubjectProfileProfileView() when profileView != null:
return profileView(_that.data);case UModerationSubjectProfileProfileViewDetailed() when profileViewDetailed != null:
return profileViewDetailed(_that.data);case _:
return null;
}
}