when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. bool testEnv,
    2. String merchantCountryCode,
    3. String currencyCode,
    4. String? merchantName,
    5. bool? isEmailRequired,
    6. bool? allowCreditCards,
    7. GooglePayBillingAddressConfig? billingAddressConfig,
    )
)

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( bool testEnv,  String merchantCountryCode,  String currencyCode,  String? merchantName,  bool? isEmailRequired,  bool? allowCreditCards,  GooglePayBillingAddressConfig? billingAddressConfig)  $default,) {final _that = this;
switch (_that) {
case _GooglePayParams():
return $default(_that.testEnv,_that.merchantCountryCode,_that.currencyCode,_that.merchantName,_that.isEmailRequired,_that.allowCreditCards,_that.billingAddressConfig);case _:
  throw StateError('Unexpected subclass');

}
}