when<TResult extends Object?> method
- @optionalTypeArgs
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 object, @JsonKey(name: "bank_account") BankAccountToken? bankAccount, CardToken? card, @JsonKey(name: "client_ip") String? clientIP, int? created, bool livemode, TokenType type, bool used) $default,) {final _that = this;
switch (_that) {
case _Token():
return $default(_that.id,_that.object,_that.bankAccount,_that.card,_that.clientIP,_that.created,_that.livemode,_that.type,_that.used);case _:
throw StateError('Unexpected subclass');
}
}