when<TResult extends Object?> method
TResult
when<TResult extends Object?>()
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? plusOne,
int? minusOne,
int? confused,
int? eyes,
int? heart,
int? hooray,
int? laugh,
int? rocket,
int totalCount,
ModelUri? url)
$default,
) {
final _that = this;
switch (_that) {
case _GithubReactionValue():
return $default(
_that.plusOne,
_that.minusOne,
_that.confused,
_that.eyes,
_that.heart,
_that.hooray,
_that.laugh,
_that.rocket,
_that.totalCount,
_that.url);
case _:
throw StateError('Unexpected subclass');
}
}