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(
String typeName,
String? typeFullLibraryName,
String name,
bool isDeprecated,
bool isStatic,
bool isConst,
bool isExperimental,
Set<String>? entryPoints,
String relativePath,
bool isReadable,
bool isWriteable)
$default,
) {
final _that = this;
switch (_that) {
case _FieldDeclaration():
return $default(
_that.typeName,
_that.typeFullLibraryName,
_that.name,
_that.isDeprecated,
_that.isStatic,
_that.isConst,
_that.isExperimental,
_that.entryPoints,
_that.relativePath,
_that.isReadable,
_that.isWriteable);
}
}