maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
  1. TResult profileViewBasic(
    1. ProfileViewBasic data
    )?,
  2. TResult profileView(
    1. ProfileView data
    )?,
  3. TResult profileViewDetailed(
    1. ProfileViewDetailed data
    )?,
  4. 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( ProfileViewBasic data)?  profileViewBasic,TResult Function( ProfileView data)?  profileView,TResult Function( ProfileViewDetailed data)?  profileViewDetailed,required TResult orElse(),}) {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 orElse();

}
}