Created
September 15, 2021 09:31
-
-
Save yeasin50/4a9d80863836b5cda8c631427724cf20 to your computer and use it in GitHub Desktop.
CustomPainter corner As decoration
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 CustomDecorationPainter extends CustomPainter { | |
final double padding; | |
final double frameSFactor; | |
CustomDecorationPainter({ | |
required this.padding, | |
required this.frameSFactor, | |
}); | |
@override | |
void paint(Canvas canvas, Size size) { | |
final frameHWidth = size.width * frameSFactor; | |
Paint paint = Paint() | |
..color = Colors.redAccent | |
..strokeCap = StrokeCap.round | |
..style = PaintingStyle.fill | |
..strokeWidth = 4; | |
/// background | |
canvas.drawRRect( | |
RRect.fromRectAndRadius( | |
Rect.fromLTRB(0, 0, size.width, size.height), | |
Radius.circular(18), | |
), | |
paint); | |
/// top left | |
canvas.drawLine( | |
Offset(0 + padding, padding), | |
Offset( | |
padding + frameHWidth, | |
padding, | |
), | |
paint..color = Colors.black, | |
); | |
canvas.drawLine( | |
Offset(0 + padding, padding), | |
Offset( | |
padding, | |
padding + frameHWidth, | |
), | |
paint..color = Colors.black, | |
); | |
/// top Right | |
canvas.drawLine( | |
Offset(size.width - padding, padding), | |
Offset(size.width - padding - frameHWidth, padding), | |
paint..color = Colors.black, | |
); | |
canvas.drawLine( | |
Offset(size.width - padding, padding), | |
Offset(size.width - padding, padding + frameHWidth), | |
paint..color = Colors.black, | |
); | |
/// Bottom Right | |
canvas.drawLine( | |
Offset(size.width - padding, size.height - padding), | |
Offset(size.width - padding - frameHWidth, size.height - padding), | |
paint..color = Colors.black, | |
); | |
canvas.drawLine( | |
Offset(size.width - padding, size.height - padding), | |
Offset(size.width - padding, size.height - padding - frameHWidth), | |
paint..color = Colors.black, | |
); | |
/// Bottom Left | |
canvas.drawLine( | |
Offset(0 + padding, size.height - padding), | |
Offset(0 + padding + frameHWidth, size.height - padding), | |
paint..color = Colors.black, | |
); | |
canvas.drawLine( | |
Offset(0 + padding, size.height - padding), | |
Offset(0 + padding, size.height - padding - frameHWidth), | |
paint..color = Colors.black, | |
); | |
} | |
@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