81 lines
1.9 KiB
Dart
81 lines
1.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:novyronst/common/const/const_color.dart';
|
|
|
|
|
|
|
|
class NyDashLine extends StatelessWidget {
|
|
final double width;
|
|
final double height;
|
|
final double dashWidth;
|
|
final double dashSpace;
|
|
final Axis direction;
|
|
|
|
const NyDashLine({
|
|
super.key,
|
|
this.width = double.infinity,
|
|
this.height = 2,
|
|
this.dashWidth = 4,
|
|
this.dashSpace = 2,
|
|
this.direction = Axis.horizontal,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return CustomPaint(
|
|
size: Size(width, height),
|
|
painter: _DashedLinePainter(
|
|
color: ConstColor.withValue('#404040'),
|
|
dashWidth: dashWidth,
|
|
dashSpace: dashSpace,
|
|
direction: direction,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _DashedLinePainter extends CustomPainter {
|
|
final Color color;
|
|
final double dashWidth;
|
|
final double dashSpace;
|
|
final Axis direction;
|
|
|
|
_DashedLinePainter({
|
|
required this.color,
|
|
required this.dashWidth,
|
|
required this.dashSpace,
|
|
required this.direction,
|
|
});
|
|
|
|
@override
|
|
void paint(Canvas canvas, Size size) {
|
|
final paint = Paint()
|
|
..color = color
|
|
..strokeWidth = direction == Axis.horizontal ? size.height : size.width
|
|
..style = PaintingStyle.stroke;
|
|
|
|
if (direction == Axis.horizontal) {
|
|
double startX = 0;
|
|
while (startX < size.width) {
|
|
canvas.drawLine(
|
|
Offset(startX, size.height / 2),
|
|
Offset(startX + dashWidth, size.height / 2),
|
|
paint,
|
|
);
|
|
startX += dashWidth + dashSpace;
|
|
}
|
|
} else {
|
|
double startY = 0;
|
|
while (startY < size.height) {
|
|
canvas.drawLine(
|
|
Offset(size.width / 2, startY),
|
|
Offset(size.width / 2, startY + dashWidth),
|
|
paint,
|
|
);
|
|
startY += dashWidth + dashSpace;
|
|
}
|
|
}
|
|
}
|
|
|
|
@override
|
|
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
|
} |