when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String? id,
    2. String? title,
    3. String? route,
    4. NavigationIcon? icon,
    5. bool? isFavourite,
    6. List<NavigationNestedItem>? nestedItems,
    )
)

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: 'id')  String? id, @JsonKey(name: 'title')  String? title, @JsonKey(name: 'onTapRoute')  String? route, @JsonKey(name: 'icon')  NavigationIcon? icon, @JsonKey(name: 'favourite')  bool? isFavourite, @JsonKey(name: 'nested')  List<NavigationNestedItem>? nestedItems)  $default,) {final _that = this;
switch (_that) {
case _NavigationItem():
return $default(_that.id,_that.title,_that.route,_that.icon,_that.isFavourite,_that.nestedItems);case _:
  throw StateError('Unexpected subclass');

}
}