performPaint method

  1. @override
void performPaint(
  1. PaintingContext context,
  2. Offset offset
)
override

RenderLayoutBox real paint things after basiclly paint box model. Override which to paint layout or intrinsic things. Used by RenderReplaced, RenderFlowLayout, RenderFlexLayout.

Implementation

@override
void performPaint(PaintingContext context, Offset offset) {
  final fill = renderStyle.isFillEmpty ? findRoot()?.renderStyle.fill ?? renderStyle.fill : renderStyle.fill;
  final stroke = renderStyle.isStrokeEmpty ? findRoot()?.renderStyle.stroke ?? renderStyle.stroke : renderStyle.stroke;
  final fillRule = renderStyle.isFillRuleEmpty ? findRoot()?.renderStyle.fillRule ?? renderStyle.fillRule : renderStyle.fillRule;
  final element = renderStyle.target as SVGElement;

  path.fillType = fillRule.fillType;

  Rect? rect = element.findRoot()?.viewBox;
  if (rect != null) {
    parseDefs(rect);
  }
  /// support svg clipPath
  if (svgClipPath != null) {
    Path? clipPath;
    switch (svgClipPath!.boxShape) {
      case BoxShape.circle:
        clipPath = svgClipPath!.clipPath;
        break;
      case BoxShape.rectangle:
        clipPath = svgClipPath!.clipPath;
        break;
    }
    context.canvas.clipPath(clipPath);
  }
  Path vpath = path.shift(offset);
  Paint? vpaint;
  if (shader != null) {
    vpaint = Paint()
      ..shader = shader
      ..style = PaintingStyle.fill;
  } else if (!fill.isNone) {
    vpaint = Paint()
      ..color = fill.resolve(renderStyle)
      ..style = PaintingStyle.fill;
  }
  if (vpaint != null) {
    context.canvas.drawPath(vpath, vpaint);
  }
  if (!stroke.isNone) {
    final strokeWidth = renderStyle.strokeWidth.computedValue;
    final strokeCap = renderStyle.strokeLinecap.strokeCap;
    final strokeJoin = renderStyle.strokeLinejoin.strokeJoin;
    Paint? v2paint = Paint()
      ..color = stroke.resolve(renderStyle)
      ..style = PaintingStyle.stroke
      ..strokeWidth = strokeWidth
      ..strokeCap = strokeCap
      ..strokeJoin = strokeJoin;
    context.canvas.drawPath(vpath, v2paint);
  }
}