when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- List<
NavigationItem> ? primaryActions, - List<
NavigationItem> ? secondaryActions, - int drawerSelectedIndex,
- int bottomBarSelectedIndex,
- List<
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(
@JsonKey(name: 'primary') List<NavigationItem>? primaryActions,
@JsonKey(name: 'secondary') List<NavigationItem>? secondaryActions,
@JsonKey(defaultValue: -1) int drawerSelectedIndex,
@JsonKey(defaultValue: 0) int bottomBarSelectedIndex)
$default,
) {
final _that = this;
switch (_that) {
case _Navigation():
return $default(_that.primaryActions, _that.secondaryActions,
_that.drawerSelectedIndex, _that.bottomBarSelectedIndex);
case _:
throw StateError('Unexpected subclass');
}
}