when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String pathId,
    3. String userId,
    4. String? userLabel,
    5. DateTime enrolledAt,
    6. String? enrolledBy,
    7. DateTime? completedAt,
    8. int currentStepPosition,
    )
)

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 pathId,  String userId,  String? userLabel,  DateTime enrolledAt,  String? enrolledBy,  DateTime? completedAt,  int currentStepPosition)  $default,) {final _that = this;
switch (_that) {
case _LearningPathEnrollmentModel():
return $default(_that.id,_that.pathId,_that.userId,_that.userLabel,_that.enrolledAt,_that.enrolledBy,_that.completedAt,_that.currentStepPosition);case _:
  throw StateError('Unexpected subclass');

}
}