loadTabData method

void loadTabData(
  1. String tabName
)

Load data for a specific tab

Implementation

void loadTabData(String tabName) {
  final tabData = tabsJson[tabName];
  if (tabData != null) {
    // Update section heights
    headerHeight.value =
        tabData['section']['subHeader'] - tabData['section']['header'];
    subHeaderHeight.value =
        tabData['section']['body'] - tabData['section']['subHeader'];
    bodyHeight.value =
        tabData['section']['subBody'] - tabData['section']['body'];
    subBodyHeight.value =
        tabData['section']['footer'] - tabData['section']['subBody'];
    footerHeight.value = 842.00 - tabData['section']['footer'];

    _updateSectionPositionsOnly();

    // Load items
    if (tabData['items'] != null) {
      final loadedItems = (tabData['items'] as List).map((item) {
        double positionY = (item['positionY'] as double);

        Map<String, dynamic> sectionPosition = tabData['section'];

        switch (item['section']) {
          case 'subHeader':
            positionY += sectionPosition['subHeader'];
            break;
          case 'subBody':
            positionY += sectionPosition['subBody'];
            break;
          case 'footer':
            positionY += sectionPosition['footer'];
            break;
        }

        return PrinterDesignerPackageListModel(
            id: item['id'],
            section: item['section'],
            label: item['label'],
            imageUrl: item['imageUrl'],
            type: item['type'],
            value: item['value'],
            prefix: item['prefix'],
            positionX: (item['positionX'] ?? 0) - 3,
            positionY: positionY,
            height: item['height'],
            width: (item['width'] ?? 0),
            isSelected: item['isSelected'],
            customText: item['customText'],
            properties: PrintDesignPackageProperties(
              fontSize: (item['properties']?['font_size'] ?? 10),
              textColor: item['properties']?['text_color'] ?? 4278190080,
              textAlign: item['properties']?['text_align'] ?? TextAlign.left.toString(),
              fontWeight: item['properties']?['font_weight'] ?? 400,
              isPrefixNeeded: item['properties']?['is_prefix_needed'] ?? false,
              direction: item['properties']?['direction'] ?? 'horizontal',
              prefixFontSize: (item['properties']?['prefix_font_size'] ?? 10),
              prefixTextColor: item['properties']?['prefix_text_color'] ?? 4278190080,
              prefixFontWeight: item['properties']?['prefix_font_weight'] ?? 400,
            ));
      }).toList();
      items.value = loadedItems;
    } else {
      items.value = [];
    }

    // Load table headers
    if (tabData['headers'] != null) {
      final headers = (tabData['headers'] as Map)['data'] as List;
      noOfTableRows.value =
          ((tabData['headers'] as Map)['tableRows'] as int).toString();

      tableVisibleHeaders.value = headers.map<Map<String, dynamic>>((item) {
        return {
          'index': item['index'],
          'label': item['label'],
          'name': item['name'],
          'value': item['value'],
          'type': item['type'],
          'width': item['width'] as double,
          'alignment': item['alignment'],
        };
      }).toList();
    } else {
      tableVisibleHeaders.value = [];
    }

    // Load sign URL
    signUrlUploaded.value = tabData['signUrl'] ?? '';
  }
}