maybeWhen<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
  1. TResult text(
    1. String? visibleIfKey,
    2. String? text,
    3. String? dataKey,
    4. PdfTextAlignment alignment,
    5. bool isBold,
    6. bool isItalic,
    )?,
  2. TResult table(
    1. String? visibleIfKey,
    2. String dataSourceKey,
    3. Map<String, String> columns,
    4. PdfTableBorderStyle borderStyle,
    )?,
  3. TResult image(
    1. String? visibleIfKey,
    2. String? imageSource,
    3. String? dataKey,
    4. double width,
    5. double height,
    6. PdfTextAlignment alignment,
    )?,
  4. TResult barcode(
    1. String? visibleIfKey,
    2. String? data,
    3. String? dataKey,
    4. BarcodeType barcodeType,
    5. PdfTextAlignment alignment,
    )?,
  5. TResult divider()?,
  6. TResult space(
    1. double height
    )?,
  7. required TResult orElse(),
})

A variant of when that fallback to an orElse callback.

It is equivalent to doing:

switch (sealedClass) {
  case Subclass(:final field):
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeWhen<TResult extends Object?>({TResult Function( String? visibleIfKey,  String? text,  String? dataKey,  PdfTextAlignment alignment,  bool isBold,  bool isItalic)?  text,TResult Function( String? visibleIfKey,  String dataSourceKey,  Map<String, String> columns,  PdfTableBorderStyle borderStyle)?  table,TResult Function( String? visibleIfKey,  String? imageSource,  String? dataKey,  double width,  double height,  PdfTextAlignment alignment)?  image,TResult Function( String? visibleIfKey,  String? data,  String? dataKey,  BarcodeType barcodeType,  PdfTextAlignment alignment)?  barcode,TResult Function()?  divider,TResult Function( double height)?  space,required TResult orElse(),}) {final _that = this;
switch (_that) {
case PdfTextElement() when text != null:
return text(_that.visibleIfKey,_that.text,_that.dataKey,_that.alignment,_that.isBold,_that.isItalic);case PdfTableElement() when table != null:
return table(_that.visibleIfKey,_that.dataSourceKey,_that.columns,_that.borderStyle);case PdfImageElement() when image != null:
return image(_that.visibleIfKey,_that.imageSource,_that.dataKey,_that.width,_that.height,_that.alignment);case PdfBarcodeElement() when barcode != null:
return barcode(_that.visibleIfKey,_that.data,_that.dataKey,_that.barcodeType,_that.alignment);case PdfDividerElement() when divider != null:
return divider();case PdfSpaceElement() when space != null:
return space(_that.height);case _:
  return orElse();

}
}