when<TResult extends Object?> method
- @optionalTypeArgs
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 name,
int suiteID,
List<int> groupIDs,
int? line,
int? column,
String? url,
int? rootLine,
int? rootColumn,
String? rootUrl,
TestMetadata metadata)
$default,
) {
final _that = this;
switch (_that) {
case _Test():
return $default(
_that.id,
_that.name,
_that.suiteID,
_that.groupIDs,
_that.line,
_that.column,
_that.url,
_that.rootLine,
_that.rootColumn,
_that.rootUrl,
_that.metadata);
case _:
throw StateError('Unexpected subclass');
}
}