when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult repoView(
    1. RepoView data
    ),
  2. required TResult repoViewNotFound(
    1. RepoViewNotFound data
    ),
  3. required TResult recordView(
    1. RecordView data
    ),
  4. required TResult recordViewNotFound(
    1. RecordViewNotFound data
    ),
  5. 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( 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);}
}