Skip to content

Instantly share code, notes, and snippets.

@felipecastrosales
Created January 19, 2023 00:02
Show Gist options
  • Save felipecastrosales/4f4954bc9e8a26eeec88dd8f19a4a5f4 to your computer and use it in GitHub Desktop.
Save felipecastrosales/4f4954bc9e8a26eeec88dd8f19a4a5f4 to your computer and use it in GitHub Desktop.
my_clipper.dart
class MyClipper extends CustomClipper<Path> {
final double _borderRadius;
final double _angle;
MyClipper({
double? borderRadius,
double? angle,
}) : _borderRadius = borderRadius ?? .1,
_angle = angle ?? degToRad(80);
@override
Path getClip(Size size) {
final borderRadius = _borderRadius * size.shortestSide;
final dx = borderRadius * cos(_angle);
final dy = borderRadius * sin(_angle);
final dX = size.height / tan(_angle);
Path path = Path()
..moveTo(borderRadius, size.height)
..quadraticBezierTo(0, size.height, dx, size.height - dy)
..lineTo(dX - dx, dy)
..quadraticBezierTo(dX, 0, dX + borderRadius, 0)
..lineTo(size.width - borderRadius, 0)
..quadraticBezierTo(size.width, 0, size.width - dx, dy)
..lineTo(size.width - dX + dx, size.height - dy)
..quadraticBezierTo(size.width - dX, size.height,
size.width - dX - borderRadius, size.height)
..close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) => false;
}
double degToRad(double deg) => deg * (pi / 180.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment