whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. PaymentSheetAppearanceColors? colors,
    2. PaymentSheetShape? shapes,
    3. PaymentSheetPrimaryButtonAppearance? primaryButton,
    4. EmbeddedPaymentElementAppearance? embeddedPaymentElement,
    5. EdgeInsetsConfig? formInsetValues,
    6. bool? applyLiquidGlass,
    7. NavigationBarStyle? navigationBarStyle,
    )?
)

A variant of when that fallback to returning null

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return null;
}

Implementation

@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( PaymentSheetAppearanceColors? colors,  PaymentSheetShape? shapes,  PaymentSheetPrimaryButtonAppearance? primaryButton,  EmbeddedPaymentElementAppearance? embeddedPaymentElement,  EdgeInsetsConfig? formInsetValues,  bool? applyLiquidGlass,  NavigationBarStyle? navigationBarStyle)?  $default,) {final _that = this;
switch (_that) {
case _PaymentSheetAppearance() when $default != null:
return $default(_that.colors,_that.shapes,_that.primaryButton,_that.embeddedPaymentElement,_that.formInsetValues,_that.applyLiquidGlass,_that.navigationBarStyle);case _:
  return null;

}
}