when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<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 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? 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():
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 _:
  throw StateError('Unexpected subclass');

}
}