when<TResult extends Object?> method
TResult
when<TResult extends Object?>(
- TResult $default(
- Color? backgroundColor,
- Color? foregroundColor,
- Color? evenBackgroundColor,
- Color? evenForegroundColor,
- Color? hoverBackgroundColor,
- Color? evenHoverBackgroundColor,
- SelectedTileColor selectedColor,
- TextStyle? textStyle,
- Widget? trailingIcon,
- bool withCheckboxIcon,
- Widget? checkboxIcon,
- Widget? selectedCheckboxIcon,
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? backgroundColor, Color? foregroundColor, Color? evenBackgroundColor, Color? evenForegroundColor, Color? hoverBackgroundColor, Color? evenHoverBackgroundColor, SelectedTileColor selectedColor, TextStyle? textStyle, Widget? trailingIcon, bool withCheckboxIcon, Widget? checkboxIcon, Widget? selectedCheckboxIcon) $default,) {final _that = this;
switch (_that) {
case _ListDataTileStyle():
return $default(_that.backgroundColor,_that.foregroundColor,_that.evenBackgroundColor,_that.evenForegroundColor,_that.hoverBackgroundColor,_that.evenHoverBackgroundColor,_that.selectedColor,_that.textStyle,_that.trailingIcon,_that.withCheckboxIcon,_that.checkboxIcon,_that.selectedCheckboxIcon);case _:
throw StateError('Unexpected subclass');
}
}