whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<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<TopicModel> children,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<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, @JsonKey(includeFromJson: false, includeToJson: false)  List<TopicModel> children)?  $default,) {final _that = this;
switch (_that) {
case _TopicModel() when $default != null:
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 _:
  return null;

}
}