when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>({
  1. required TResult googlePay(
    1. GooglePayParams googlePayParams,
    2. GooglePayPaymentMethodParams googlePayPaymentMethodParams
    ),
  2. required TResult applePay(
    1. ApplePayParams applePayParams
    ),
  3. required TResult web(
    1. PlatformPayWebPaymentRequestCreateOptions options
    ),
})

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?>({required TResult Function( GooglePayParams googlePayParams,  GooglePayPaymentMethodParams googlePayPaymentMethodParams)  googlePay,required TResult Function( ApplePayParams applePayParams)  applePay,required TResult Function( PlatformPayWebPaymentRequestCreateOptions options)  web,}) {final _that = this;
switch (_that) {
case PlatformPayPaymentMethodParamsGooglePay():
return googlePay(_that.googlePayParams,_that.googlePayPaymentMethodParams);case PlatformPayPaymentMethodParamsApplePay():
return applePay(_that.applePayParams);case PlatformPayPaymentMethodParamsWeb():
return web(_that.options);}
}