@@ -4,6 +4,8 @@ import 'dart:ui';
44import 'package:codelessly_api/codelessly_api.dart' ;
55import 'package:flutter/material.dart' ;
66
7+ import '../../utils/extensions.dart' ;
8+
79/// This stroke painter is needed because Flutter's built in stroke for
810/// containers only does inside strokes and doesn't do dotted borders.
911///
@@ -87,6 +89,8 @@ class StrokePainter extends CustomPainter {
8789
8890 @override
8991 void paint (Canvas canvas, Size size) {
92+ // Whether the shape that we're outlining is so thin that it is effectively
93+ // a line rather than a quadrilateral.
9094 final bool isLine =
9195 size.shortestSide <= strokeWidth * 2 && boxShape == BoxShape .rectangle;
9296 final bool isHorizLine = isLine && size.width <= strokeWidth * 2 ;
@@ -96,7 +100,7 @@ class StrokePainter extends CustomPainter {
96100 ..color = color
97101 ..style = PaintingStyle .stroke
98102 ..strokeWidth = strokeWidth
99- ..strokeCap = StrokeCap .values[ strokeCap.index]
103+ ..strokeCap = strokeCap.flutterStrokeCap
100104 ..strokeMiterLimit = strokeMiterLimit;
101105
102106 // If the stroke is dotted, we take a completely different rendering
@@ -174,12 +178,20 @@ class StrokePainter extends CustomPainter {
174178 parallelTangentVector.dy * isInside * isCenter,
175179 parallelTangentVector.dx * isOutside,
176180 ) *
181+ // Multiply by the stroke thickness to figure out the distance
182+ // needed from the start position to the stroke.
177183 strokeWidth *
184+
185+ // If it's a center stroke, we need to divide the normal by 2.
186+ // It will be rendered twice, once inside, once outside,
187+ // achieving the center stroke effect.
178188 (strokeAlign == StrokeAlignC .center ? 0.5 : 1 );
179189
180190 canvas.drawLine (
181191 tangent.position,
182192 tangent.position + normal,
193+
194+ // The width of the "needle" on the "balloon"
183195 paint..strokeWidth = dashDistance,
184196 );
185197
@@ -188,7 +200,12 @@ class StrokePainter extends CustomPainter {
188200 if (strokeAlign == StrokeAlignC .center) {
189201 canvas.drawLine (
190202 tangent.position,
203+
204+ // Rendering the needle as if it were on the inside of the
205+ // balloon.
191206 tangent.position + normal * - 1 ,
207+
208+ // The width of the "needle" on the "balloon"
192209 paint..strokeWidth = dashDistance,
193210 );
194211 }
0 commit comments