updateItemProperties method

void updateItemProperties({
  1. required String itemId,
  2. Map<String, dynamic>? properties,
  3. double? positionX,
  4. double? positionY,
  5. double? height,
  6. double? width,
  7. String? customText,
  8. String? value,
  9. String? prefix,
})

Implementation

void updateItemProperties({
  required String itemId,
  Map<String, dynamic>? properties,
  double? positionX,
  double? positionY,
  double? height,
  double? width,
  String? customText,
  String? value,
  String? prefix,
}) {
  // If we have multiple items selected, update all of them
  if (selectedItemIds.isNotEmpty) {
    for (var selectedId in selectedItemIds) {
      final index = items.indexWhere((item) => item.id == selectedId);
      if (index != -1) {
        final item = items[index];
        final updatedProperties = PrintDesignPackageProperties(
          fontSize:
          properties?['fontSize'] as double? ?? item.properties?.fontSize,
          fontWeight: properties?['fontWeight'] as int? ??
              item.properties?.fontWeight,
          textColor:
          properties?['textColor'] as int? ?? item.properties?.textColor,
          textAlign: properties?['textAlign'] as String? ??
              item.properties?.textAlign,
          direction: properties?['direction'] as String? ??
              item.properties?.direction,
          isPrefixNeeded: properties?['is_prefix_needed'] as bool? ??
              item.properties?.isPrefixNeeded,
          prefixFontSize: properties?['prefix_fontSize'] as double? ??
              item.properties?.prefixFontSize,
          prefixFontWeight: properties?['prefix_fontWeight'] as int? ??
              item.properties?.prefixFontWeight,
          prefixTextColor: properties?['prefix_textColor'] as int? ??
              item.properties?.prefixTextColor,
        );
        items[index] = PrinterDesignerPackageListModel(
          id: item.id,
          type: item.type,
          label: item.label,
          prefix: prefix ?? item.prefix,
          value: value ?? item.value,
          imageUrl: item.imageUrl,
          positionX: positionX ?? item.positionX,
          positionY: positionY ?? item.positionY,
          height: height ?? item.height,
          width: width ?? item.width,
          section: item.section,
          isSelected: true,
          customText: customText ?? item.customText,
          properties: updatedProperties,
        );
      }
    }
  } else {
    // Single item update (existing code)
    final index = items.indexWhere((item) => item.id == itemId);
    if (index != -1) {
      final item = items[index];
      final updatedProperties = PrintDesignPackageProperties(
        fontSize:
        properties?['fontSize'] as double? ?? item.properties?.fontSize,
        fontWeight:
        properties?['fontWeight'] as int? ?? item.properties?.fontWeight,
        textAlign:
        properties?['textAlign'] as String? ?? item.properties?.textAlign,
        textColor:
        properties?['textColor'] as int? ?? item.properties?.textColor,
        direction:
        properties?['direction'] as String? ?? item.properties?.direction,
        isPrefixNeeded: properties?['is_prefix_needed'] as bool? ??
            item.properties?.isPrefixNeeded,
        prefixFontSize: properties?['prefix_fontSize'] as double? ??
            item.properties?.prefixFontSize,
        prefixFontWeight: properties?['prefix_fontWeight'] as int? ??
            item.properties?.prefixFontWeight,
        prefixTextColor: properties?['prefix_textColor'] as int? ??
            item.properties?.prefixTextColor,
      );
      items[index] = PrinterDesignerPackageListModel(
        id: item.id,
        type: item.type,
        label: item.label,
        prefix: prefix ?? item.prefix,
        value: value ?? item.value,
        imageUrl: item.imageUrl,
        positionX: positionX ?? item.positionX,
        positionY: positionY ?? item.positionY,
        height: height ?? item.height,
        width: width ?? item.width,
        section: item.section,
        isSelected: item.isSelected,
        customText: customText ?? item.customText,
        properties: updatedProperties,
      );
    }
  }
}