when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. Color? backgroundColor,
    2. Color? foregroundColor,
    3. Color? evenBackgroundColor,
    4. Color? evenForegroundColor,
    5. Color? hoverBackgroundColor,
    6. Color? evenHoverBackgroundColor,
    7. SelectedTileColor selectedColor,
    8. TextStyle? textStyle,
    9. Widget? trailingIcon,
    10. bool withCheckboxIcon,
    11. Widget? checkboxIcon,
    12. 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');

}
}