dev
dart 36 lines 903 Bytes
Raw
1 import 'package:flutter/material.dart';
2
3 class DottedDivider extends StatelessWidget {
4 final Color color;
5
6 const DottedDivider({super.key, required this.color});
7
8 @override
9 Widget build(BuildContext context) => SizedBox(
10 width: double.infinity,
11 child: CustomPaint(
12 painter: _DashedLinePainter(color: color),
13 ),
14 );
15 }
16
17 class _DashedLinePainter extends CustomPainter {
18 final Color color;
19
20 const _DashedLinePainter({required this.color});
21
22 @override
23 void paint(Canvas canvas, Size size) {
24 double dashWidth = 9, dashSpace = 5, startX = 0;
25 final paint = Paint()
26 ..color = color
27 ..strokeWidth = 1;
28 while (startX < size.width) {
29 canvas.drawLine(Offset(startX, 0), Offset(startX + dashWidth, 0), paint);
30 startX += dashWidth + dashSpace;
31 }
32 }
33
34 @override
35 bool shouldRepaint(CustomPainter oldDelegate) => false;
36 }