Last active
February 24, 2025 08:47
-
-
Save RohmanBenyRiyanto/9db6e06d580481b44e67168905d5964f to your computer and use it in GitHub Desktop.
Create a custom ticket card display in flutter
This file contains hidden or 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 CustomTicket extends CustomClipper<Path> { | |
@override | |
Path getClip(Size size) { | |
final path = Path(); | |
//Radius | |
path.addRRect( | |
RRect.fromRectAndRadius( | |
Rect.fromLTWH(0, 0, size.width, size.height), | |
const Radius.circular(8), | |
), | |
); | |
// Left Round In | |
path.addOval( | |
Rect.fromCircle( | |
center: Offset(0, (size.height / 3) * 1.8), // Position Roun In Left | |
radius: 10, // Size | |
), | |
); | |
// Right Round In | |
path.addOval( | |
Rect.fromCircle( | |
center: Offset(size.width, (size.height / 3) * 1.8), // Position Roun In Right | |
radius: 10, // Size | |
), | |
); | |
// Horizontal Line Dash | |
const dashWidth = 10; | |
const dashSpace = 5; | |
final dashCount = size.width ~/ (dashWidth + dashSpace); | |
for (var i = 0; i < dashCount; i++) { | |
path.addRect( | |
Rect.fromLTWH( | |
i * (dashWidth + dashSpace).toDouble() + 10, | |
(size.height / 3) * 1.8, | |
dashWidth.toDouble(), | |
1, | |
), | |
); | |
} | |
path.fillType = PathFillType.evenOdd; | |
return path; | |
} | |
@override | |
bool shouldReclip(CustomClipper oldClipper) { | |
return true; | |
} | |
} |
This file contains hidden or 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
ClipPath( | |
clipper: CustomTicket(), // <-- CustomClipper | |
child: Container( | |
color: backgroundColor ?? ThemesColor.orangeTwoColor, // <-- background color | |
height: 150.h, // <-- height | |
width: ThemesMargin.screenHeight(), // <-- width | |
child: // <-- child can be any widget | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
PREVIEW