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