whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. String id,
    2. String? targetUserId,
    3. String? targetOrgId,
    4. SubscriptionSource source,
    5. String? externalId,
    6. PlanTier plan,
    7. SubscriptionStatus status,
    8. DateTime? currentPeriodStart,
    9. DateTime? currentPeriodEnd,
    10. bool cancelAtPeriodEnd,
    11. int? seats,
    12. Map<String, dynamic> metadata,
    13. DateTime createdAt,
    14. 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? targetUserId,  String? targetOrgId,  SubscriptionSource source,  String? externalId,  PlanTier plan,  SubscriptionStatus status,  DateTime? currentPeriodStart,  DateTime? currentPeriodEnd,  bool cancelAtPeriodEnd,  int? seats,  Map<String, dynamic> metadata,  DateTime createdAt,  DateTime updatedAt)?  $default,) {final _that = this;
switch (_that) {
case _Subscription() when $default != null:
return $default(_that.id,_that.targetUserId,_that.targetOrgId,_that.source,_that.externalId,_that.plan,_that.status,_that.currentPeriodStart,_that.currentPeriodEnd,_that.cancelAtPeriodEnd,_that.seats,_that.metadata,_that.createdAt,_that.updatedAt);case _:
  return null;

}
}