whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
  1. TResult? profileViewDetailed(
    1. ProfileViewDetailed data
    )?,
  2. TResult? blockedPost(
    1. BlockedPost data
    )?,
  3. TResult? generatorView(
    1. GeneratorView data
    )?,
  4. TResult? notFoundPost(
    1. NotFoundPost data
    )?,
  5. TResult? postView(
    1. PostView data
    )?,
  6. TResult? starterPackView(
    1. StarterPackView data
    )?,
  7. TResult? unknown(
    1. Map<String, dynamic> 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( ProfileViewDetailed data)?  profileViewDetailed,TResult? Function( BlockedPost data)?  blockedPost,TResult? Function( GeneratorView data)?  generatorView,TResult? Function( NotFoundPost data)?  notFoundPost,TResult? Function( PostView data)?  postView,TResult? Function( StarterPackView data)?  starterPackView,TResult? Function( Map<String, dynamic> data)?  unknown,}) {final _that = this;
switch (_that) {
case UNotificationGetGroupedNotificationsRelatedViewsProfileViewDetailed() when profileViewDetailed != null:
return profileViewDetailed(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsBlockedPost() when blockedPost != null:
return blockedPost(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsGeneratorView() when generatorView != null:
return generatorView(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsNotFoundPost() when notFoundPost != null:
return notFoundPost(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsPostView() when postView != null:
return postView(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsStarterPackView() when starterPackView != null:
return starterPackView(_that.data);case UNotificationGetGroupedNotificationsRelatedViewsUnknown() when unknown != null:
return unknown(_that.data);case _:
  return null;

}
}