when<TResult extends Object?> method
- TResult $default(
- 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,
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');
}
}