generateCurrentTabData method

Map<String, dynamic> generateCurrentTabData()

Generate data for the current tab

Implementation

Map<String, dynamic> generateCurrentTabData() {
  final sortedVisibleHeaders = tableVisibleHeaders.toList()
    ..sort((a, b) => (a['index'] as int).compareTo(b['index'] as int));

  final List<Map<String, dynamic>> headersWithProperties =
  sortedVisibleHeaders.map((table) {
    return {
      'index': table['index'],
      'label': table['label'],
      'name': table['name'],
      'width': table['width'] ?? 70,
      'type': table['type'],
      'alignment': table['alignment'],
      'value': table['value'],
    };
  }).toList();

  Map<String, dynamic> section = {
    'header': sectionYPositions['header'],
    'subHeader': sectionYPositions['subHeader'],
    'body': sectionYPositions['body'],
    'subBody': sectionYPositions['subBody'],
    'footer': sectionYPositions['footer'],
  };

  return {
    'section': section,
    'headers': {
      'tableRows': int.parse(noOfTableRows.value),
      'data': headersWithProperties,
    },
    'items': items.map((item) {
      double positionY = item.positionY ?? 0;

      switch (item.section) {
        case 'subHeader':
          positionY -= headerHeight.value;
          break;
        case 'subBody':
          positionY -=
          (headerHeight.value + subHeaderHeight.value + bodyHeight.value);
          break;
        case 'footer':
          positionY -= (headerHeight.value +
              subHeaderHeight.value +
              bodyHeight.value +
              subBodyHeight.value);
          break;
      }

      return {
        'id': item.id,
        'label': item.label,
        'type': item.type,
        'value': item.value,
        'prefix': item.prefix,
        'imageUrl': item.imageUrl,
        'positionX': (item.positionX ?? 0) + 3,
        'positionY': positionY,
        'height': (item.height ?? 0),
        'width': (item.width ?? 0),
        'section': item.section,
        'customText': item.customText,
        'properties': {
          'font_size': (item.properties?.fontSize ?? 10),
          'font_weight': item.properties?.fontWeight ?? 400,
          'text_align': item.properties?.textAlign ?? 'TextAlign.left',
          'text_color': item.properties?.textColor ?? 4278190080,
          'direction': item.properties?.direction ?? 'horizontal',
          'is_prefix_needed': item.properties?.isPrefixNeeded ?? false,
        },
      };
    }).toList(),
  };
}