Skip to content

Instantly share code, notes, and snippets.

@mirkancal
Created April 18, 2024 09:45
Show Gist options
  • Save mirkancal/5f97c7eb1efdff71467b077dc958534a to your computer and use it in GitHub Desktop.
Save mirkancal/5f97c7eb1efdff71467b077dc958534a to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
class QRCornerPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final paint = Paint()
..color = Colors.white
..style = PaintingStyle.fill;
final cornerLength = size.width * 0.1;
final cornerThickness = cornerLength * 0.2;
// Top-left corner
canvas.drawRect(Rect.fromLTWH(0, 0, cornerLength, cornerThickness), paint);
canvas.drawRect(Rect.fromLTWH(0, 0, cornerThickness, cornerLength), paint);
// Top-right corner
canvas.drawRect(
Rect.fromLTWH(
size.width - cornerLength, 0, cornerLength, cornerThickness),
paint);
canvas.drawRect(
Rect.fromLTWH(
size.width - cornerThickness, 0, cornerThickness, cornerLength),
paint);
// Bottom-left corner
canvas.drawRect(
Rect.fromLTWH(
0, size.height - cornerThickness, cornerLength, cornerThickness),
paint);
canvas.drawRect(
Rect.fromLTWH(
0, size.height - cornerLength, cornerThickness, cornerLength),
paint);
// Bottom-right corner
canvas.drawRect(
Rect.fromLTWH(size.width - cornerLength, size.height - cornerThickness,
cornerLength, cornerThickness),
paint);
canvas.drawRect(
Rect.fromLTWH(size.width - cornerThickness, size.height - cornerLength,
cornerThickness, cornerLength),
paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
@mirkancal
Copy link
Author

mirkancal commented Apr 18, 2024

Center(
  child: CustomPaint(
    size: Size.square(300),
      painter: QRCornerPainter(),
    ),
),
Description of Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment