whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. int? id,
    2. String? body,
    3. String? previousBody,
    4. String? diffHunk,
    5. String? path,
    6. int? position,
    7. int? originalPosition,
    8. String? commitId,
    9. String? originalCommitId,
    10. String? sha,
    11. String? state,
    12. int? reviewId,
    13. GithubTimelineEvent event,
    14. GithubUserModel? user,
    15. GithubUserModel? from,
    16. GithubUserModel? to,
    17. GithubProjectModel? project,
    18. GithubMilestoneValue? milestone,
    19. GithubReactionValue? reaction,
    20. GithubIssueModel? issue,
    21. GithubPullRequestModel? pullRequest,
    22. GithubLabelValue? label,
    23. ModelUri? url,
    24. ModelUri? pullRequestUrl,
    25. ModelUri? commitUrl,
    26. ModelUri? links,
    27. ModelUri? issueUrl,
    28. ModelTimestamp createdAt,
    29. ModelTimestamp updatedAt,
    30. bool fromServer,
    )?
)

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(
          int? id,
          String? body,
          String? previousBody,
          String? diffHunk,
          String? path,
          int? position,
          int? originalPosition,
          String? commitId,
          String? originalCommitId,
          String? sha,
          String? state,
          int? reviewId,
          GithubTimelineEvent event,
          @jsonParam GithubUserModel? user,
          @jsonParam GithubUserModel? from,
          @jsonParam GithubUserModel? to,
          @jsonParam GithubProjectModel? project,
          @jsonParam GithubMilestoneValue? milestone,
          @jsonParam GithubReactionValue? reaction,
          @jsonParam GithubIssueModel? issue,
          @jsonParam GithubPullRequestModel? pullRequest,
          @jsonParam GithubLabelValue? label,
          ModelUri? url,
          ModelUri? pullRequestUrl,
          ModelUri? commitUrl,
          ModelUri? links,
          ModelUri? issueUrl,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)?
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubPullRequestTimelineModel() when $default != null:
      return $default(
          _that.id,
          _that.body,
          _that.previousBody,
          _that.diffHunk,
          _that.path,
          _that.position,
          _that.originalPosition,
          _that.commitId,
          _that.originalCommitId,
          _that.sha,
          _that.state,
          _that.reviewId,
          _that.event,
          _that.user,
          _that.from,
          _that.to,
          _that.project,
          _that.milestone,
          _that.reaction,
          _that.issue,
          _that.pullRequest,
          _that.label,
          _that.url,
          _that.pullRequestUrl,
          _that.commitUrl,
          _that.links,
          _that.issueUrl,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      return null;
  }
}