when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- int? id,
- String? nodeId,
- int? number,
- String? state,
- String? title,
- String? body,
- String? mergeCommitSha,
- String? mergeableState,
- String? authorAssociation,
- bool draft,
- bool merged,
- bool mergeable,
- bool rebaseable,
- bool maintainerCanModify,
- int commentsCount,
- int commitsCount,
- int additionsCount,
- int deletionsCount,
- int changedFilesCount,
- int reviewCommentCount,
- GithubRepositoryModelRef? repository,
- GithubUserModelRef? user,
- GithubUserModelRef? mergedBy,
- List<
GithubUserModelRef?> requestedReviewers, - List<
GithubLabelValue> labels, - GithubPullRequestHeadValue? head,
- GithubPullRequestHeadValue? base,
- GithubMilestoneValue? milestone,
- ModelUri? htmlUrl,
- ModelUri? diffUrl,
- ModelUri? patchUrl,
- ModelTimestamp? closedAt,
- ModelTimestamp? mergedAt,
- ModelTimestamp createdAt,
- ModelTimestamp updatedAt,
- 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,
String? nodeId,
int? number,
String? state,
String? title,
String? body,
String? mergeCommitSha,
String? mergeableState,
String? authorAssociation,
bool draft,
bool merged,
bool mergeable,
bool rebaseable,
bool maintainerCanModify,
int commentsCount,
int commitsCount,
int additionsCount,
int deletionsCount,
int changedFilesCount,
int reviewCommentCount,
@refParam GithubRepositoryModelRef? repository,
@refParam GithubUserModelRef? user,
@refParam GithubUserModelRef? mergedBy,
@refParam List<GithubUserModelRef> requestedReviewers,
@jsonParam List<GithubLabelValue> labels,
@jsonParam GithubPullRequestHeadValue? head,
@jsonParam GithubPullRequestHeadValue? base,
@jsonParam GithubMilestoneValue? milestone,
ModelUri? htmlUrl,
ModelUri? diffUrl,
ModelUri? patchUrl,
ModelTimestamp? closedAt,
ModelTimestamp? mergedAt,
ModelTimestamp createdAt,
ModelTimestamp updatedAt,
bool fromServer)
$default,
) {
final _that = this;
switch (_that) {
case _GithubPullRequestModel():
return $default(
_that.id,
_that.nodeId,
_that.number,
_that.state,
_that.title,
_that.body,
_that.mergeCommitSha,
_that.mergeableState,
_that.authorAssociation,
_that.draft,
_that.merged,
_that.mergeable,
_that.rebaseable,
_that.maintainerCanModify,
_that.commentsCount,
_that.commitsCount,
_that.additionsCount,
_that.deletionsCount,
_that.changedFilesCount,
_that.reviewCommentCount,
_that.repository,
_that.user,
_that.mergedBy,
_that.requestedReviewers,
_that.labels,
_that.head,
_that.base,
_that.milestone,
_that.htmlUrl,
_that.diffUrl,
_that.patchUrl,
_that.closedAt,
_that.mergedAt,
_that.createdAt,
_that.updatedAt,
_that.fromServer);
case _:
throw StateError('Unexpected subclass');
}
}