when<TResult extends Object?> method
TResult
when<TResult extends Object?>({
- required TResult string(
- String labelBuilder(
- T data
- Color? backgroundColor,
- TextStyle? labelStyle,
- OutlinedBorder? shape,
- Color? deleteIconColor,
- Widget? deleteIcon,
- Widget? avatar,
- BoxConstraints? avatarBoxConstraints,
- EdgeInsetsGeometry? labelPadding,
- BorderSide side,
- String labelBuilder(
- required TResult custom(
- Widget builder(
- BuildContext context,
- T data,
- void delete()
- Widget builder(
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?>({required TResult Function( String Function(T data) labelBuilder, Color? backgroundColor, TextStyle? labelStyle, OutlinedBorder? shape, Color? deleteIconColor, Widget? deleteIcon, Widget? avatar, BoxConstraints? avatarBoxConstraints, EdgeInsetsGeometry? labelPadding, BorderSide side) string,required TResult Function( Widget Function(BuildContext context, T data, void Function() delete) builder) custom,}) {final _that = this;
switch (_that) {
case DataDisplayBuilderString():
return string(_that.labelBuilder,_that.backgroundColor,_that.labelStyle,_that.shape,_that.deleteIconColor,_that.deleteIcon,_that.avatar,_that.avatarBoxConstraints,_that.labelPadding,_that.side);case DataDisplayBuilderWidget():
return custom(_that.builder);}
}