You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fluffychat/lib/pangea/message_token_text/dotted_border_painter.dart

49 lines
1.2 KiB
Dart

import 'package:flutter/material.dart';
class DottedBorderPainter extends CustomPainter {
final Color color;
final double strokeWidth;
final double dashWidth;
final double dashSpace;
final BorderRadius borderRadius;
DottedBorderPainter({
required this.color,
this.strokeWidth = 2.0,
this.dashWidth = 4.0,
this.dashSpace = 4.0,
required this.borderRadius,
});
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = color
..strokeWidth = strokeWidth
..style = PaintingStyle.stroke;
final path = Path()
..addRRect(
borderRadius.toRRect(Rect.fromLTWH(0, 0, size.width, size.height)),
);
final dashPath = Path();
final pathMetrics = path.computeMetrics();
for (final pathMetric in pathMetrics) {
double distance = 0.0;
while (distance < pathMetric.length) {
final segment = pathMetric.extractPath(distance, distance + dashWidth);
dashPath.addPath(segment, Offset.zero);
distance += dashWidth + dashSpace;
}
}
canvas.drawPath(dashPath, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}