when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int? id,
    2. int? number,
    3. String? title,
    4. String? body,
    5. String? bodyHtml,
    6. String? bodyText,
    7. String? state,
    8. String? stateReason,
    9. String? activeLockReason,
    10. String? authorAssociation,
    11. String? nodeId,
    12. bool draft,
    13. bool locked,
    14. int commentsCount,
    15. GithubRepositoryModelRef? repository,
    16. GithubUserModel? user,
    17. GithubUserModel? assignee,
    18. List<GithubUserModel> assignees,
    19. GithubUserModel? closedBy,
    20. List<GithubLabelValue> labels,
    21. ModelUri? url,
    22. ModelUri? htmlUrl,
    23. ModelUri? commentsUrl,
    24. ModelUri? eventsUrl,
    25. ModelUri? labelsUrl,
    26. ModelUri? repositoryUrl,
    27. ModelUri? timelineUrl,
    28. GithubReactionValue? reactions,
    29. ModelTimestamp? closedAt,
    30. ModelTimestamp createdAt,
    31. ModelTimestamp updatedAt,
    32. bool fromServer,
    )
)

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?>(
  TResult Function(
          int? id,
          int? number,
          String? title,
          String? body,
          String? bodyHtml,
          String? bodyText,
          String? state,
          String? stateReason,
          String? activeLockReason,
          String? authorAssociation,
          String? nodeId,
          bool draft,
          bool locked,
          int commentsCount,
          @refParam GithubRepositoryModelRef? repository,
          @jsonParam GithubUserModel? user,
          @jsonParam GithubUserModel? assignee,
          @jsonParam List<GithubUserModel> assignees,
          @jsonParam GithubUserModel? closedBy,
          @jsonParam List<GithubLabelValue> labels,
          ModelUri? url,
          ModelUri? htmlUrl,
          ModelUri? commentsUrl,
          ModelUri? eventsUrl,
          ModelUri? labelsUrl,
          ModelUri? repositoryUrl,
          ModelUri? timelineUrl,
          @jsonParam GithubReactionValue? reactions,
          ModelTimestamp? closedAt,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubIssueModel():
      return $default(
          _that.id,
          _that.number,
          _that.title,
          _that.body,
          _that.bodyHtml,
          _that.bodyText,
          _that.state,
          _that.stateReason,
          _that.activeLockReason,
          _that.authorAssociation,
          _that.nodeId,
          _that.draft,
          _that.locked,
          _that.commentsCount,
          _that.repository,
          _that.user,
          _that.assignee,
          _that.assignees,
          _that.closedBy,
          _that.labels,
          _that.url,
          _that.htmlUrl,
          _that.commentsUrl,
          _that.eventsUrl,
          _that.labelsUrl,
          _that.repositoryUrl,
          _that.timelineUrl,
          _that.reactions,
          _that.closedAt,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      throw StateError('Unexpected subclass');
  }
}