Created
October 5, 2024 16:27
-
-
Save jorwan/b32ef58fdace6cf022565a11c827f75e to your computer and use it in GitHub Desktop.
dashed line example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(const MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
const MyApp({super.key}); | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: SizedBox( | |
width: double.infinity, | |
child: CustomPaint( | |
painter: DashedLinePainter(), | |
) | |
), | |
), | |
), | |
); | |
} | |
} | |
class DashedLinePainter extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
double dashWidth = 9, dashSpace = 5, startX = 0; | |
final paint = Paint() | |
..color = Colors.grey | |
..strokeWidth = 1; | |
while (startX < size.width) { | |
canvas.drawLine(Offset(startX, 0), Offset(startX + dashWidth, 0), paint); | |
startX += dashWidth + dashSpace; | |
} | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment