Last active
December 29, 2023 14:29
-
-
Save nhancv/3d6ac4b6b684ccc517270bf145b9b43b to your computer and use it in GitHub Desktop.
Flutter custom painter: rounded rect and arrow
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
class _MenuBoxBackground extends CustomPainter { | |
@override | |
void paint(Canvas canvas, Size size) { | |
final Paint paint = Paint() | |
..color = Colors.white | |
..strokeWidth = 1.W | |
..style = PaintingStyle.fill; | |
final double triangleH = 10.H; | |
final double triangleW = 25.0.W; | |
final double width = size.width; | |
final double height = size.height; | |
final Path trianglePath = Path() | |
..moveTo(width / 2 - triangleW / 2, height) | |
..lineTo(width / 2, triangleH + height) | |
..lineTo(width / 2 + triangleW / 2, height) | |
..lineTo(width / 2 - triangleW / 2, height); | |
canvas.drawPath(trianglePath, paint); | |
final BorderRadius borderRadius = BorderRadius.circular(15.W); | |
final Rect rect = Rect.fromLTRB(0, 0, width, height); | |
final RRect outer = borderRadius.toRRect(rect); | |
canvas.drawRRect(outer, paint); | |
} | |
@override | |
bool shouldRepaint(CustomPainter oldDelegate) => false; | |
} |
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
CustomPaint( | |
painter: _MenuBoxBackground(), | |
child: Container( | |
padding: EdgeInsets.only( | |
left: 15.W, right: 15.W, bottom: 20.H, top: 20.H), | |
child: ..., | |
), | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment