when<TResult extends Object?> method
- TResult $default()
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, GrantType grantType, PlanTier? plan, int? discountPct, int? aiBoostMessages, int? trialExtensionDays, DateTime startsAt, DateTime? endsAt, String? reason, String? grantedBy, DateTime createdAt, DateTime? revokedAt, String? revokedBy) $default,) {final _that = this;
switch (_that) {
case _AdminGrant():
return $default(_that.id,_that.targetUserId,_that.targetOrgId,_that.grantType,_that.plan,_that.discountPct,_that.aiBoostMessages,_that.trialExtensionDays,_that.startsAt,_that.endsAt,_that.reason,_that.grantedBy,_that.createdAt,_that.revokedAt,_that.revokedBy);case _:
throw StateError('Unexpected subclass');
}
}