paint method
- Canvas canvas,
- Rect rect, {
- double? gapStart,
- double gapExtent = 0.0,
- double gapPercentage = 0.0,
- TextDirection? textDirection,
override
Draw the custom shape around rect.
The borderSide defines the line's color and weight.
The top side of the border may be interrupted by a single gap
if gapExtent is non-null. In that case the gap begins at
gapStart - gapPadding (assuming that the textDirection is TextDirection.ltr).
The gap's width is (gapPadding + gapExtent + gapPadding) * gapPercentage.
Implementation
@override
void paint(
Canvas canvas,
Rect rect, {
double? gapStart,
double gapExtent = 0.0,
double gapPercentage = 0.0,
TextDirection? textDirection,
}) {
assert(gapPercentage >= 0.0 && gapPercentage <= 1.0);
final Paint paint = borderSide.toPaint();
final Rect deflatedRect = rect.deflate(borderSide.width / 2.0);
if (gapStart == null || gapExtent <= 0.0 || gapPercentage == 0.0) {
// Draw the shape without a gap.
if (shape is OutlinedBorder) {
final outlinedShape = shape as OutlinedBorder;
// Create a copy with our border side.
final OutlinedBorder shapedBorder = outlinedShape.copyWith(side: borderSide);
shapedBorder.paint(canvas, deflatedRect, textDirection: textDirection);
} else {
canvas.drawPath(shape.getOuterPath(deflatedRect, textDirection: textDirection), paint);
}
} else {
final double extent = lerpDouble(0.0, gapExtent + gapPadding * 2.0, gapPercentage)!;
final double start = switch (textDirection!) {
TextDirection.rtl => gapStart + gapPadding - extent,
TextDirection.ltr => gapStart - gapPadding,
};
final Path path = _gapBorderPath(
deflatedRect,
math.max(0.0, start),
extent,
textDirection: textDirection,
);
canvas.drawPath(path, paint);
}
}