when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- String? name,
- String? path,
- String? content,
- String? sha,
- String? type,
- String? encoding,
- String? patch,
- String? status,
- GithubUserModelRef? committer,
- int size,
- int additionsCount,
- int deletionsCount,
- int changesCount,
- ModelUri? rawUrl,
- ModelUri? blobUrl,
- ModelUri? htmlUrl,
- ModelUri? gitUrl,
- ModelUri? downloadUrl,
- List<
GithubContentModel> ? children, - 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(
String? name,
String? path,
String? content,
String? sha,
String? type,
String? encoding,
String? patch,
String? status,
@refParam GithubUserModelRef committer,
int size,
int additionsCount,
int deletionsCount,
int changesCount,
ModelUri? rawUrl,
ModelUri? blobUrl,
ModelUri? htmlUrl,
ModelUri? gitUrl,
ModelUri? downloadUrl,
@jsonParam List<GithubContentModel>? children,
bool fromServer)
$default,
) {
final _that = this;
switch (_that) {
case _GithubContentModel():
return $default(
_that.name,
_that.path,
_that.content,
_that.sha,
_that.type,
_that.encoding,
_that.patch,
_that.status,
_that.committer,
_that.size,
_that.additionsCount,
_that.deletionsCount,
_that.changesCount,
_that.rawUrl,
_that.blobUrl,
_that.htmlUrl,
_that.gitUrl,
_that.downloadUrl,
_that.children,
_that.fromServer);
case _:
throw StateError('Unexpected subclass');
}
}