when<TResult extends Object?> method
TResult
when<TResult extends Object?>()
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');
}
}