Skip to content

Instantly share code, notes, and snippets.

@jorwan
Created October 5, 2024 16:27
Show Gist options
  • Save jorwan/b32ef58fdace6cf022565a11c827f75e to your computer and use it in GitHub Desktop.
Save jorwan/b32ef58fdace6cf022565a11c827f75e to your computer and use it in GitHub Desktop.
dashed line example
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