when<TResult extends Object?> method
- @optionalTypeArgs
- TResult $default(
- String id,
- String object,
- String? addressCity,
- String? addressCountry,
- String? addressLine1,
- VerificationCheck? addressLine1Check,
- String? addressLine2,
- String? addressState,
- String? addressZip,
- VerificationCheck? addressZipCheck,
- CardTokenBrand? brand,
- String? country,
- String? currency,
- VerificationCheck? cvcCheck,
- String? dynamicLast4,
- int? expMonth,
- int? expYear,
- String? fingerprint,
- CardFundingType? funding,
- String? last4,
- Map<
String, dynamic> metadata, - String? name,
- CardTokenizationMethod? tokenizationMethod,
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: "address_city") String? addressCity, @JsonKey(name: "address_country") String? addressCountry, @JsonKey(name: "address_line1") String? addressLine1, @JsonKey(name: "address_line1_check") VerificationCheck? addressLine1Check, @JsonKey(name: "address_line2") String? addressLine2, @JsonKey(name: "address_state") String? addressState, @JsonKey(name: "address_zip") String? addressZip, @JsonKey(name: "address_zip_check") VerificationCheck? addressZipCheck, CardTokenBrand? brand, String? country, String? currency, @JsonKey(name: "cvc_check") VerificationCheck? cvcCheck, @JsonKey(name: "dynamic_last4") String? dynamicLast4, @JsonKey(name: "exp_month") int? expMonth, @JsonKey(name: "exp_year") int? expYear, String? fingerprint, CardFundingType? funding, String? last4, Map<String, dynamic> metadata, String? name, @JsonKey(name: "tokenization_method") CardTokenizationMethod? tokenizationMethod) $default,) {final _that = this;
switch (_that) {
case _CardToken():
return $default(_that.id,_that.object,_that.addressCity,_that.addressCountry,_that.addressLine1,_that.addressLine1Check,_that.addressLine2,_that.addressState,_that.addressZip,_that.addressZipCheck,_that.brand,_that.country,_that.currency,_that.cvcCheck,_that.dynamicLast4,_that.expMonth,_that.expYear,_that.fingerprint,_that.funding,_that.last4,_that.metadata,_that.name,_that.tokenizationMethod);case _:
throw StateError('Unexpected subclass');
}
}