whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String orgId,
    3. String invitedUserId,
    4. String invitedByUserId,
    5. String role,
    6. String status,
    7. DateTime createdAt,
    8. DateTime? resolvedAt,
    9. String? orgName,
    10. String? inviterName,
    11. String? invitedEmail,
    12. String? invitedUsername,
    )?
)

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 invitedUserId,  String invitedByUserId,  String role,  String status,  DateTime createdAt,  DateTime? resolvedAt,  String? orgName,  String? inviterName,  String? invitedEmail,  String? invitedUsername)?  $default,) {final _that = this;
switch (_that) {
case _OrgInvitationModel() when $default != null:
return $default(_that.id,_that.orgId,_that.invitedUserId,_that.invitedByUserId,_that.role,_that.status,_that.createdAt,_that.resolvedAt,_that.orgName,_that.inviterName,_that.invitedEmail,_that.invitedUsername);case _:
  return null;

}
}