when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. int? id,
    2. String? name,
    3. String? fullName,
    4. GithubUserModelRef? owner,
    5. GithubOrganizationModelRef? organization,
    6. String? language,
    7. GithubLicenseValue? license,
    8. GithubRepositoryPermissionValue? permissions,
    9. bool isPrivate,
    10. bool isFork,
    11. bool isTemplate,
    12. String? description,
    13. String? masterBranch,
    14. String? mergeCommitMessage,
    15. String? mergeCommitTitle,
    16. String? squashMergeCommitMessage,
    17. String? squashMergeCommitTitle,
    18. String? nodeId,
    19. String? tempCloneToken,
    20. String? visibility,
    21. List<String> topics,
    22. bool archived,
    23. bool disabled,
    24. bool hasIssues,
    25. bool hasWiki,
    26. bool hasDownloads,
    27. bool hasPages,
    28. bool hasDiscussions,
    29. bool hasProjects,
    30. bool allowAutoMerge,
    31. bool allowForking,
    32. bool allowMergeCommit,
    33. bool allowRebaseMerge,
    34. bool allowSquashMerge,
    35. bool allowUpdateBranch,
    36. bool anonymousAccessEnabled,
    37. bool deleteBranchOnMerge,
    38. bool webCommitSignoffRequired,
    39. int size,
    40. int stargazersCount,
    41. int watchersCount,
    42. int forksCount,
    43. int openIssuesCount,
    44. int subscribersCount,
    45. int networkCount,
    46. ModelUri? htmlUrl,
    47. ModelUri? cloneUrl,
    48. ModelUri? sshUrl,
    49. ModelUri? svnUrl,
    50. ModelUri? gitUrl,
    51. ModelUri? homepageUrl,
    52. ModelUri? archiveUrl,
    53. ModelUri? assigneesUrl,
    54. ModelUri? blobsUrl,
    55. ModelUri? branchesUrl,
    56. ModelUri? collaboratorsUrl,
    57. ModelUri? commentsUrl,
    58. ModelUri? commitsUrl,
    59. ModelUri? compareUrl,
    60. ModelUri? contentsUrl,
    61. ModelUri? contributorsUrl,
    62. ModelUri? deploymentsUrl,
    63. ModelUri? downloadsUrl,
    64. ModelUri? eventsUrl,
    65. ModelUri? forksUrl,
    66. ModelUri? gitCommitsUrl,
    67. ModelUri? gitRefsUrl,
    68. ModelUri? gitTagsUrl,
    69. ModelUri? hooksUrl,
    70. ModelUri? issueCommentUrl,
    71. ModelUri? issueEventsUrl,
    72. ModelUri? issuesUrl,
    73. ModelUri? keysUrl,
    74. ModelUri? labelsUrl,
    75. ModelUri? languagesUrl,
    76. ModelUri? mergesUrl,
    77. ModelUri? milestonesUrl,
    78. ModelUri? mirrorUrl,
    79. ModelUri? notificationsUrl,
    80. ModelUri? pullsUrl,
    81. ModelUri? releasesUrl,
    82. ModelUri? stargazersUrl,
    83. ModelUri? statusesUrl,
    84. ModelUri? subscribersUrl,
    85. ModelUri? subscriptionUrl,
    86. ModelUri? tagsUrl,
    87. ModelUri? teamsUrl,
    88. ModelUri? treesUrl,
    89. GithubRepositoryModelRef? templateRepository,
    90. ModelTimestamp? starredAt,
    91. ModelTimestamp? pushedAt,
    92. ModelTimestamp createdAt,
    93. ModelTimestamp updatedAt,
    94. 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,
          @searchParam String? name,
          @searchParam String? fullName,
          @refParam GithubUserModelRef owner,
          @refParam GithubOrganizationModelRef organization,
          @searchParam String? language,
          @jsonParam GithubLicenseValue? license,
          @jsonParam GithubRepositoryPermissionValue? permissions,
          bool isPrivate,
          bool isFork,
          bool isTemplate,
          @searchParam String? description,
          String? masterBranch,
          String? mergeCommitMessage,
          String? mergeCommitTitle,
          String? squashMergeCommitMessage,
          String? squashMergeCommitTitle,
          String? nodeId,
          String? tempCloneToken,
          String? visibility,
          List<String> topics,
          bool archived,
          bool disabled,
          bool hasIssues,
          bool hasWiki,
          bool hasDownloads,
          bool hasPages,
          bool hasDiscussions,
          bool hasProjects,
          bool allowAutoMerge,
          bool allowForking,
          bool allowMergeCommit,
          bool allowRebaseMerge,
          bool allowSquashMerge,
          bool allowUpdateBranch,
          bool anonymousAccessEnabled,
          bool deleteBranchOnMerge,
          bool webCommitSignoffRequired,
          int size,
          int stargazersCount,
          int watchersCount,
          int forksCount,
          int openIssuesCount,
          int subscribersCount,
          int networkCount,
          ModelUri? htmlUrl,
          ModelUri? cloneUrl,
          ModelUri? sshUrl,
          ModelUri? svnUrl,
          ModelUri? gitUrl,
          ModelUri? homepageUrl,
          ModelUri? archiveUrl,
          ModelUri? assigneesUrl,
          ModelUri? blobsUrl,
          ModelUri? branchesUrl,
          ModelUri? collaboratorsUrl,
          ModelUri? commentsUrl,
          ModelUri? commitsUrl,
          ModelUri? compareUrl,
          ModelUri? contentsUrl,
          ModelUri? contributorsUrl,
          ModelUri? deploymentsUrl,
          ModelUri? downloadsUrl,
          ModelUri? eventsUrl,
          ModelUri? forksUrl,
          ModelUri? gitCommitsUrl,
          ModelUri? gitRefsUrl,
          ModelUri? gitTagsUrl,
          ModelUri? hooksUrl,
          ModelUri? issueCommentUrl,
          ModelUri? issueEventsUrl,
          ModelUri? issuesUrl,
          ModelUri? keysUrl,
          ModelUri? labelsUrl,
          ModelUri? languagesUrl,
          ModelUri? mergesUrl,
          ModelUri? milestonesUrl,
          ModelUri? mirrorUrl,
          ModelUri? notificationsUrl,
          ModelUri? pullsUrl,
          ModelUri? releasesUrl,
          ModelUri? stargazersUrl,
          ModelUri? statusesUrl,
          ModelUri? subscribersUrl,
          ModelUri? subscriptionUrl,
          ModelUri? tagsUrl,
          ModelUri? teamsUrl,
          ModelUri? treesUrl,
          @refParam GithubRepositoryModelRef? templateRepository,
          ModelTimestamp? starredAt,
          ModelTimestamp? pushedAt,
          ModelTimestamp createdAt,
          ModelTimestamp updatedAt,
          bool fromServer)
      $default,
) {
  final _that = this;
  switch (_that) {
    case _GithubRepositoryModel():
      return $default(
          _that.id,
          _that.name,
          _that.fullName,
          _that.owner,
          _that.organization,
          _that.language,
          _that.license,
          _that.permissions,
          _that.isPrivate,
          _that.isFork,
          _that.isTemplate,
          _that.description,
          _that.masterBranch,
          _that.mergeCommitMessage,
          _that.mergeCommitTitle,
          _that.squashMergeCommitMessage,
          _that.squashMergeCommitTitle,
          _that.nodeId,
          _that.tempCloneToken,
          _that.visibility,
          _that.topics,
          _that.archived,
          _that.disabled,
          _that.hasIssues,
          _that.hasWiki,
          _that.hasDownloads,
          _that.hasPages,
          _that.hasDiscussions,
          _that.hasProjects,
          _that.allowAutoMerge,
          _that.allowForking,
          _that.allowMergeCommit,
          _that.allowRebaseMerge,
          _that.allowSquashMerge,
          _that.allowUpdateBranch,
          _that.anonymousAccessEnabled,
          _that.deleteBranchOnMerge,
          _that.webCommitSignoffRequired,
          _that.size,
          _that.stargazersCount,
          _that.watchersCount,
          _that.forksCount,
          _that.openIssuesCount,
          _that.subscribersCount,
          _that.networkCount,
          _that.htmlUrl,
          _that.cloneUrl,
          _that.sshUrl,
          _that.svnUrl,
          _that.gitUrl,
          _that.homepageUrl,
          _that.archiveUrl,
          _that.assigneesUrl,
          _that.blobsUrl,
          _that.branchesUrl,
          _that.collaboratorsUrl,
          _that.commentsUrl,
          _that.commitsUrl,
          _that.compareUrl,
          _that.contentsUrl,
          _that.contributorsUrl,
          _that.deploymentsUrl,
          _that.downloadsUrl,
          _that.eventsUrl,
          _that.forksUrl,
          _that.gitCommitsUrl,
          _that.gitRefsUrl,
          _that.gitTagsUrl,
          _that.hooksUrl,
          _that.issueCommentUrl,
          _that.issueEventsUrl,
          _that.issuesUrl,
          _that.keysUrl,
          _that.labelsUrl,
          _that.languagesUrl,
          _that.mergesUrl,
          _that.milestonesUrl,
          _that.mirrorUrl,
          _that.notificationsUrl,
          _that.pullsUrl,
          _that.releasesUrl,
          _that.stargazersUrl,
          _that.statusesUrl,
          _that.subscribersUrl,
          _that.subscriptionUrl,
          _that.tagsUrl,
          _that.teamsUrl,
          _that.treesUrl,
          _that.templateRepository,
          _that.starredAt,
          _that.pushedAt,
          _that.createdAt,
          _that.updatedAt,
          _that.fromServer);
    case _:
      throw StateError('Unexpected subclass');
  }
}