when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. @JsonKey.new(toJson: UserInterfaceStyleKey.toJson) ThemeMode? style,
    2. PaymentSheetAppearance? appearance,
    3. String? setupIntentClientSecret,
    4. String customerId,
    5. String customerEphemeralKeySecret,
    6. String? merchantDisplayName,
    7. bool? allowsRemovalOfLastSavedPaymentMethod,
    8. String? headerTextForSelectionScreen,
    9. BillingDetails? defaultBillingDetails,
    10. BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,
    11. String? returnURL,
    12. String? removeSavedPaymentMethodMessage,
    13. bool applePayEnabled,
    14. bool googlePayEnabled,
    15. @JsonKey.new(toJson: _cardBrandListToJson) List<CardBrand>? preferredNetworks,
    16. CardBrandAcceptance? cardBrandAcceptance,
    17. bool? opensCardScannerAutomatically,
    ), {
  2. required TResult adapter(
    1. String? setupIntentClientSecret,
    2. String customerId,
    3. IntentConfiguration? intentConfiguration,
    4. String? customerEphemeralKeySecret,
    5. @JsonKey.new(toJson: UserInterfaceStyleKey.toJson) ThemeMode? style,
    6. PaymentSheetAppearance? appearance,
    7. String? merchantDisplayName,
    8. bool? allowsRemovalOfLastSavedPaymentMethod,
    9. String? headerTextForSelectionScreen,
    10. BillingDetails? defaultBillingDetails,
    11. BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,
    12. String? returnURL,
    13. String? removeSavedPaymentMethodMessage,
    14. bool applePayEnabled,
    15. bool googlePayEnabled,
    16. @JsonKey.new(toJson: _cardBrandListToJson) List<CardBrand>? preferredNetworks,
    17. CardBrandAcceptance? cardBrandAcceptance,
    ),
  3. required TResult session(
    1. String? setupIntentClientSecret,
    2. String? customerId,
    3. IntentConfiguration intentConfiguration,
    4. String? customerEphemeralKeySecret,
    5. @JsonKey.new(toJson: UserInterfaceStyleKey.toJson) ThemeMode? style,
    6. PaymentSheetAppearance? appearance,
    7. String? merchantDisplayName,
    8. bool? allowsRemovalOfLastSavedPaymentMethod,
    9. String? headerTextForSelectionScreen,
    10. BillingDetails? defaultBillingDetails,
    11. BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,
    12. String? returnURL,
    13. String? removeSavedPaymentMethodMessage,
    14. bool applePayEnabled,
    15. bool googlePayEnabled,
    16. @JsonKey.new(toJson: _cardBrandListToJson) List<CardBrand>? preferredNetworks,
    17. CardBrandAcceptance? cardBrandAcceptance,
    ),
})

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(@JsonKey(toJson: UserInterfaceStyleKey.toJson)  ThemeMode? style,  PaymentSheetAppearance? appearance,  String? setupIntentClientSecret,  String customerId,  String customerEphemeralKeySecret,  String? merchantDisplayName,  bool? allowsRemovalOfLastSavedPaymentMethod,  String? headerTextForSelectionScreen,  BillingDetails? defaultBillingDetails,  BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,  String? returnURL,  String? removeSavedPaymentMethodMessage,  bool applePayEnabled,  bool googlePayEnabled, @JsonKey(toJson: _cardBrandListToJson)  List<CardBrand>? preferredNetworks,  CardBrandAcceptance? cardBrandAcceptance,  bool? opensCardScannerAutomatically)  $default,{required TResult Function( String? setupIntentClientSecret,  String customerId,  IntentConfiguration? intentConfiguration,  String? customerEphemeralKeySecret, @JsonKey(toJson: UserInterfaceStyleKey.toJson)  ThemeMode? style,  PaymentSheetAppearance? appearance,  String? merchantDisplayName,  bool? allowsRemovalOfLastSavedPaymentMethod,  String? headerTextForSelectionScreen,  BillingDetails? defaultBillingDetails,  BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,  String? returnURL,  String? removeSavedPaymentMethodMessage,  bool applePayEnabled,  bool googlePayEnabled, @JsonKey(toJson: _cardBrandListToJson)  List<CardBrand>? preferredNetworks,  CardBrandAcceptance? cardBrandAcceptance)  adapter,required TResult Function( String? setupIntentClientSecret,  String? customerId,  IntentConfiguration intentConfiguration,  String? customerEphemeralKeySecret, @JsonKey(toJson: UserInterfaceStyleKey.toJson)  ThemeMode? style,  PaymentSheetAppearance? appearance,  String? merchantDisplayName,  bool? allowsRemovalOfLastSavedPaymentMethod,  String? headerTextForSelectionScreen,  BillingDetails? defaultBillingDetails,  BillingDetailsCollectionConfiguration? billingDetailsCollectionConfiguration,  String? returnURL,  String? removeSavedPaymentMethodMessage,  bool applePayEnabled,  bool googlePayEnabled, @JsonKey(toJson: _cardBrandListToJson)  List<CardBrand>? preferredNetworks,  CardBrandAcceptance? cardBrandAcceptance)  session,}) {final _that = this;
switch (_that) {
case _CustomerSheetInitParamsDeprecated():
return $default(_that.style,_that.appearance,_that.setupIntentClientSecret,_that.customerId,_that.customerEphemeralKeySecret,_that.merchantDisplayName,_that.allowsRemovalOfLastSavedPaymentMethod,_that.headerTextForSelectionScreen,_that.defaultBillingDetails,_that.billingDetailsCollectionConfiguration,_that.returnURL,_that.removeSavedPaymentMethodMessage,_that.applePayEnabled,_that.googlePayEnabled,_that.preferredNetworks,_that.cardBrandAcceptance,_that.opensCardScannerAutomatically);case _CustomerSheetInitParamsAdapter():
return adapter(_that.setupIntentClientSecret,_that.customerId,_that.intentConfiguration,_that.customerEphemeralKeySecret,_that.style,_that.appearance,_that.merchantDisplayName,_that.allowsRemovalOfLastSavedPaymentMethod,_that.headerTextForSelectionScreen,_that.defaultBillingDetails,_that.billingDetailsCollectionConfiguration,_that.returnURL,_that.removeSavedPaymentMethodMessage,_that.applePayEnabled,_that.googlePayEnabled,_that.preferredNetworks,_that.cardBrandAcceptance);case _CustomerSheetInitParamsSession():
return session(_that.setupIntentClientSecret,_that.customerId,_that.intentConfiguration,_that.customerEphemeralKeySecret,_that.style,_that.appearance,_that.merchantDisplayName,_that.allowsRemovalOfLastSavedPaymentMethod,_that.headerTextForSelectionScreen,_that.defaultBillingDetails,_that.billingDetailsCollectionConfiguration,_that.returnURL,_that.removeSavedPaymentMethodMessage,_that.applePayEnabled,_that.googlePayEnabled,_that.preferredNetworks,_that.cardBrandAcceptance);case _:
  throw StateError('Unexpected subclass');

}
}