whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String orgId,
    3. String assignmentId,
    4. String targetMastery,
    5. DateTime? targetDate,
    6. String status,
    7. String createdBy,
    8. DateTime createdAt,
    9. DateTime updatedAt,
    )?
)

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 orgId,  String assignmentId,  String targetMastery,  DateTime? targetDate,  String status,  String createdBy,  DateTime createdAt,  DateTime updatedAt)?  $default,) {final _that = this;
switch (_that) {
case _LearningObjective() when $default != null:
return $default(_that.id,_that.orgId,_that.assignmentId,_that.targetMastery,_that.targetDate,_that.status,_that.createdBy,_that.createdAt,_that.updatedAt);case _:
  return null;

}
}