addItem method
void
addItem({})
Implementation
void addItem({required String type,
required String label,
required String section,
required String value,
required String prefix,
required String urlString,
Map<String, dynamic>? properties}) {
clearSelection();
List<String> itemLabels = [
'Header Text',
'SubHeader Text',
'SubBody Text',
'Footer Text',
];
///check the devPrintBlue and change this with showSnackbar
// Check if item already exists
if (items
.any((item) => item.label == label && !itemLabels.contains(label))) {
devPrintBlue('This component already exists in the canvas');
return;
}
final sectionY = sectionYPositions[section]!;
const size = Size(120, 30);
// final size = componentSizes[label] ?? const Size(120, 30);
Offset initialPos = Offset(20, sectionY + 10);
// Create properties with custom values if provided
PrintDesignPackageProperties itemProperties = PrintDesignPackageProperties(
fontSize: properties?['font_size']?.toDouble() ?? 10.0,
fontWeight:
properties?['font_weight']?.toInt() ?? FontWeight.normal.value,
textAlign: properties?['text_align'] ?? TextAlign.left.toString(),
textColor: properties?['text_color']?.toInt() ?? Colors.black.value,
isPrefixNeeded: properties?['is_prefix_needed'] ?? false,
);
PrinterDesignerPackageListModel newItem = PrinterDesignerPackageListModel(
id: UniqueKey().toString(),
type: type,
label: label,
value: value,
prefix: prefix,
imageUrl: urlString,
positionX: initialPos.dx,
positionY: initialPos.dy,
height: size.height,
width: size.width,
section: section,
isSelected: true,
properties: itemProperties,
);
Offset? placementPosition =
_calculatePlacementPosition(newItem, initialPos, null);
if (placementPosition != null) {
items.add(PrinterDesignerPackageListModel(
id: UniqueKey().toString(),
type: type,
label: label,
value: value,
prefix: prefix,
imageUrl: urlString,
positionX: placementPosition.dx,
positionY: placementPosition.dy,
height: size.height,
width: size.width,
section: section,
isSelected: true,
properties: itemProperties,
));
} else {
devPrintBlue("Could not find space in the $section section for: $label");
}
}