Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RohmanBenyRiyanto/9db6e06d580481b44e67168905d5964f to your computer and use it in GitHub Desktop.
Save RohmanBenyRiyanto/9db6e06d580481b44e67168905d5964f to your computer and use it in GitHub Desktop.
Create a custom ticket card display in flutter
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;
}
}
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
),
);
@RohmanBenyRiyanto
Copy link
Author

PREVIEW

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment