when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- 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,
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( 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():
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 _:
throw StateError('Unexpected subclass');
}
}