whenOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
  1. TResult? $default(
    1. Color background,
    2. Color foreground,
    3. Color borderColor,
    4. Color loadingColor,
    5. Color disableBackground,
    6. double borderWidth,
    7. bool isEnable,
    8. double elevation,
    9. double paddingHorizontal,
    10. double paddingVertical,
    11. double textSize,
    12. Widget? prefixIcon,
    13. Widget? suffixIcon,
    14. Widget? centerIcon,
    15. TextStyle? textStyle,
    )?
)

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( Color background,  Color foreground,  Color borderColor,  Color loadingColor,  Color disableBackground,  double borderWidth,  bool isEnable,  double elevation,  double paddingHorizontal,  double paddingVertical,  double textSize,  Widget? prefixIcon,  Widget? suffixIcon,  Widget? centerIcon,  TextStyle? textStyle)?  $default,) {final _that = this;
switch (_that) {
case _XButtonStyle() when $default != null:
return $default(_that.background,_that.foreground,_that.borderColor,_that.loadingColor,_that.disableBackground,_that.borderWidth,_that.isEnable,_that.elevation,_that.paddingHorizontal,_that.paddingVertical,_that.textSize,_that.prefixIcon,_that.suffixIcon,_that.centerIcon,_that.textStyle);case _:
  return null;

}
}