Created
November 19, 2023 20:04
-
-
Save ruan65/c7fd10fa21cd09750a3486f3c1b72046 to your computer and use it in GitHub Desktop.
Custom painer with hole inside
This file contains 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'; | |
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