when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String? bookId,
    3. String domainId,
    4. String? parentTopicId,
    5. String title,
    6. int depth,
    7. int sortOrder,
    8. int? pageStart,
    9. int? pageEnd,
    10. String? curriculumLevelId,
    11. List<Topic> children,
    )
)

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 id,  String? bookId,  String domainId,  String? parentTopicId,  String title,  int depth,  int sortOrder,  int? pageStart,  int? pageEnd,  String? curriculumLevelId,  List<Topic> children)  $default,) {final _that = this;
switch (_that) {
case _Topic():
return $default(_that.id,_that.bookId,_that.domainId,_that.parentTopicId,_that.title,_that.depth,_that.sortOrder,_that.pageStart,_that.pageEnd,_that.curriculumLevelId,_that.children);case _:
  throw StateError('Unexpected subclass');

}
}