Skip to content

Instantly share code, notes, and snippets.

@ruan65
Created November 19, 2023 20:04
Show Gist options
  • Save ruan65/c7fd10fa21cd09750a3486f3c1b72046 to your computer and use it in GitHub Desktop.
Save ruan65/c7fd10fa21cd09750a3486f3c1b72046 to your computer and use it in GitHub Desktop.
Custom painer with hole inside
import 'package:flutter/material.dart';
class TransparentRoundedRectangle extends StatelessWidget {
const TransparentRoundedRectangle({super.key});
@override
Widget build(BuildContext context) {
return CustomPaint(
painter: CandlePainter(),
);
}
}
class CandlePainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.orange;
canvas.drawPath(
Path.combine(
PathOperation.difference,
Path()..addRect(Rect.fromLTRB(0, 0, size.width, size.height)),
Path()
..addRRect(RRect.fromLTRBR(
0, 0, size.width, size.height, Radius.circular(30)))
..close(),
),
paint,
);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment