ReportElement.fromJson constructor

ReportElement.fromJson(
  1. Map<String, dynamic> json
)

Restores an element from VPS-compatible JSON.

Implementation

factory ReportElement.fromJson(Map<String, dynamic> json) {
  final summary = json['summary'] as Map<String, dynamic>? ?? const {};
  final grouping = json['grouping'] as Map<String, dynamic>? ?? const {};
  final chart = json['chart'] as Map<String, dynamic>? ?? const {};
  return ReportElement(
    id: json['id'],
    type: ElementType.values.byName(json['type']),
    x: (json['x'] as num).toDouble(),
    y: (json['y'] as num).toDouble(),
    width: (json['width'] as num).toDouble(),
    height: (json['height'] as num).toDouble(),
    value: json['value'] ?? '',
    fontSize: (json['fontSize'] ?? 12).toDouble(),
    bold: json['bold'] ?? false,
    textAlign: json['textAlign'] ?? 'left',
    fontFamily: json['fontFamily'] ?? 'Helvetica',
    printColor: json['printColor'] ?? 0xff172033,
    dataSource: json['dataSource'] ?? 'items',
    columns: (json['columns'] as List<dynamic>? ?? const [])
        .map((column) => ReportColumn.fromJson(column))
        .toList(),
    rowHeight: (json['rowHeight'] ?? 24).toDouble(),
    headerColor: json['headerColor'] ?? 0xff3156d3,
    headerTextColor: json['headerTextColor'] ?? 0xffffffff,
    alternateRowColor: json['alternateRowColor'] ?? 0xfff3f5f9,
    showBorders: json['showBorders'] ?? true,
    imageBase64: json['imageBase64'] ?? '',
    imageName: json['imageName'] ?? '',
    imageFit: json['imageFit'] ?? 'contain',
    showSummary: summary['enabled'] ?? true,
    showSubtotal: summary['showSubtotal'] ?? true,
    showTaxes: summary['showTaxes'] ?? true,
    amountExpression: summary['amountExpression'] ?? 'total',
    subtotalLabel: summary['subtotalLabel'] ?? 'Zwischensumme',
    discountPercent: (summary['discountPercent'] ?? 0).toDouble(),
    discountLabel: summary['discountLabel'] ?? 'Rabatt',
    totalLabel: summary['totalLabel'] ?? 'Gesamtbetrag',
    taxRules: (summary['taxRules'] as List<dynamic>? ?? const [])
        .map((rule) => TaxRule.fromJson(rule))
        .toList(),
    aggregateRules: (summary['aggregateRules'] as List<dynamic>? ?? const [])
        .map((rule) => AggregateRule.fromJson(rule))
        .toList(),
    lineDirection: json['lineDirection'] ?? 'horizontal',
    lineThickness: (json['lineThickness'] ?? 1.5).toDouble(),
    codeValue: json['codeValue'] ?? '',
    barcodeType: json['barcodeType'] ?? 'ean13',
    showCodeText: json['showCodeText'] ?? true,
    band: json['band'] ?? 'body',
    visibilityCondition: json['visibilityCondition'] ?? '',
    pageVisibility: ElementPageVisibility.values.firstWhere(
      (value) => value.name == (json['pageVisibility'] ?? 'all'),
      orElse: () => ElementPageVisibility.all,
    ),
    locked: json['locked'] ?? false,
    hidden: json['hidden'] ?? false,
    keepTogether: json['keepTogether'] ?? false,
    flow: json['flow'] ?? false,
    section: json['section'] ?? 'body',
    groupBy: grouping['field'] ?? '',
    groupHeader: grouping['header'] ?? '{{group}}',
    groupFooter: grouping['footer'] ?? 'Zwischensumme',
    showGroupHeader: grouping['showHeader'] ?? true,
    showGroupFooter: grouping['showFooter'] ?? true,
    chartType: ChartType.values.firstWhere(
      (value) => value.name == (chart['type'] ?? 'bar'),
      orElse: () => ChartType.bar,
    ),
    chartCategoryField: chart['categoryField'] ?? 'label',
    chartValueExpression: chart['valueExpression'] ?? 'value',
    chartShowLegend: chart['showLegend'] ?? true,
    chartShowLabels: chart['showLabels'] ?? true,
    chartColors: (chart['colors'] as List<dynamic>? ?? const [])
        .whereType<num>()
        .map((value) => value.toInt())
        .toList(),
  );
}