whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>()
A variant of when
that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? whenOrNull<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() when $default != null:
return $default(
_that.plusOne,
_that.minusOne,
_that.confused,
_that.eyes,
_that.heart,
_that.hooray,
_that.laugh,
_that.rocket,
_that.totalCount,
_that.url);
case _:
return null;
}
}