when<TResult extends Object?> method
- @optionalTypeArgs
- required TResult repoView(
- RepoView data
- required TResult repoViewNotFound(
- RepoViewNotFound data
- required TResult recordView(
- RecordView data
- required TResult recordViewNotFound(
- RecordViewNotFound 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( RepoView data) repoView,required TResult Function( RepoViewNotFound data) repoViewNotFound,required TResult Function( RecordView data) recordView,required TResult Function( RecordViewNotFound data) recordViewNotFound,required TResult Function( Map<String, dynamic> data) unknown,}) {final _that = this;
switch (_that) {
case UModEventViewDetailSubjectRepoView():
return repoView(_that.data);case UModEventViewDetailSubjectRepoViewNotFound():
return repoViewNotFound(_that.data);case UModEventViewDetailSubjectRecordView():
return recordView(_that.data);case UModEventViewDetailSubjectRecordViewNotFound():
return recordViewNotFound(_that.data);case UModEventViewDetailSubjectUnknown():
return unknown(_that.data);}
}