render method
Widget
render(
{ - required Node node,
- required Size parentSize,
})
Implementation
Widget render({
required final figma.Node node,
required final Size parentSize,
}) {
if (!node.visible) return const SizedBox.shrink();
if (node is! figma.Vector) {
throw ArgumentError('Node must be a VECTOR node');
}
final constraintsAdapter = FigmaConstraintsAdapter(node, parentSize);
// Get base dimensions
final baseWidth = _getWidth(node);
final baseHeight = _getHeight(node);
if (baseWidth == null || baseHeight == null) {
return const SizedBox.shrink();
}
// Get stroke properties
final strokeWeight = _getStrokeWeight(node) ?? 0.0;
final strokeAlign = _getStrokeAlign(node) ?? figma.StrokeAlign.center;
// Calculate stroke padding (how much the stroke extends beyond the path)
double strokeOutsidePadding = 0.0;
switch (strokeAlign) {
case figma.StrokeAlign.inside:
strokeOutsidePadding = 0.0; // Stroke is fully inside the path
break;
case figma.StrokeAlign.center:
strokeOutsidePadding = strokeWeight / 2.0; // Half of stroke is outside
break;
case figma.StrokeAlign.outside:
strokeOutsidePadding = strokeWeight; // Stroke is fully outside the path
break;
}
// Calculate final dimensions including stroke
final width = baseWidth + strokeOutsidePadding * 2;
final height = baseHeight + strokeOutsidePadding * 2;
final result = RepaintBoundary(
child: CustomPaint(
isComplex: true,
painter: _VectorPainter(
fills: _getFills(node),
strokes: _getStrokes(node),
strokeWeight: strokeWeight,
strokeAlign: strokeAlign,
fillGeometry: _getFillGeometry(node),
strokeGeometry: _getStrokeGeometry(node),
strokeCap: _getStrokeCap(node),
strokeJoin: _getStrokeJoin(node),
),
size: Size(width, height),
),
);
return constraintsAdapter.applyConstraints(result);
}