when<TResult extends Object?> method
TResult
when<TResult extends Object?>({
- required TResult invalidShippingField(
- InvalidShippingField field,
- String? message
- required TResult unserviceableShippingAddress(
- String? message
- required TResult invalidCouponCode(
- String? message
- required TResult expiredCouponCode(
- String? message
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( InvalidShippingField field, String? message) invalidShippingField,required TResult Function( String? message) unserviceableShippingAddress,required TResult Function( String? message) invalidCouponCode,required TResult Function( String? message) expiredCouponCode,}) {final _that = this;
switch (_that) {
case _ApplePaySheetErrorInvalidShipping():
return invalidShippingField(_that.field,_that.message);case _ApplePaySheetErrorUnserviceableShipping():
return unserviceableShippingAddress(_that.message);case _ApplePaySheetErrorInvalidCouponCode():
return invalidCouponCode(_that.message);case _ApplePaySheetErrorExpiredCouponCode():
return expiredCouponCode(_that.message);case _:
throw StateError('Unexpected subclass');
}
}