when<TResult extends Object?> method

  1. @optionalTypeArgs
TResult when<TResult extends Object?>(
  1. TResult $default(
    1. String title,
    2. @JsonKey.new(unknownEnumValue: ReportSource.messages) ReportSource source,
    3. @JsonKey.new(unknownEnumValue: ReportAlgorithm.auto) ReportAlgorithm algorithm,
    4. List<ReportTemplateColInput> cols,
    5. String script,
    )
)

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( String title, @JsonKey(unknownEnumValue: ReportSource.messages)  ReportSource source, @JsonKey(unknownEnumValue: ReportAlgorithm.auto)  ReportAlgorithm algorithm,  List<ReportTemplateColInput> cols,  String script)  $default,) {final _that = this;
switch (_that) {
case _ReportTemplatePageInput():
return $default(_that.title,_that.source,_that.algorithm,_that.cols,_that.script);case _:
  throw StateError('Unexpected subclass');

}
}