handleResizeUpdate method
void
handleResizeUpdate(
- Offset currentPosition
)
Implementation
void handleResizeUpdate(Offset currentPosition) {
if (resizingItemId.value == null ||
originalItemSize.value == null ||
resizeStartPosition.value == null) return;
final index = items.indexWhere((item) => item.id == resizingItemId.value);
if (index == -1) return;
final item = items[index];
final delta = currentPosition - resizeStartPosition.value!;
// Get the default size for this component type
// final defaultSize = componentSizes[item.label ?? ''] ?? Size(100, 20);
// Get section constraints
final sectionY = sectionYPositions[item.section!]!;
final sectionHeight = _getSectionHeight(item.section!);
final maxWidth = 585.0; // Maximum width of the canvas
// Calculate maximum allowed size based on position
final maxAllowedWidth = maxWidth - (item.positionX ?? 0);
final maxAllowedHeight = sectionY + sectionHeight - (item.positionY ?? 0);
// Calculate new size with constraints
double newWidth = originalItemSize.value!.width + delta.dx;
double newHeight = originalItemSize.value!.height + delta.dy;
// Apply minimum constraints
newWidth = newWidth < 50 ? 50 : newWidth;
if ([
'Invoice Number',
'Invoice Date',
'LPO Number',
'Payment Terms',
'Sales Person',
'Amount Words'
].contains(item.label)) {
double maxValue = item.properties?.direction == 'horizontal' ? 15 : 33;
newHeight = newHeight < maxValue ? maxValue : newHeight;
} else {
newHeight = newHeight < 15 ? 15 : newHeight;
}
// Apply maximum constraints
newWidth = newWidth > maxAllowedWidth ? maxAllowedWidth : newWidth;
newHeight = newHeight > maxAllowedHeight ? maxAllowedHeight : newHeight;
items[index] = PrinterDesignerPackageListModel(
id: item.id,
type: item.type,
label: item.label,
value: item.value,
prefix: item.prefix,
imageUrl: item.imageUrl,
positionX: item.positionX,
positionY: item.positionY,
height: newHeight,
width: newWidth,
section: item.section,
isSelected: item.isSelected,
customText: item.customText,
properties: item.properties,
);
}