when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String id,
    2. String object,
    3. BankAccountToken? bankAccount,
    4. CardToken? card,
    5. String? clientIP,
    6. int? created,
    7. bool livemode,
    8. TokenType type,
    9. bool used,
    )
)

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');

}
}