getClip method

  1. @override
Path getClip(
  1. Size size
)
override

Returns a description of the clip given that the render object being clipped is of the given size.

Implementation

@override
Path getClip(Size size) {
  Path rectPath =
      Path()..addRect(Rect.fromLTWH(0, 0, size.width, size.height));

  Path cutouts = Path();

  if (top) {
    cutouts.addOval(
      Rect.fromCircle(center: Offset(size.width / 2, 0), radius: radius),
    );
  }

  if (bottom) {
    cutouts.addOval(
      Rect.fromCircle(
        center: Offset(size.width / 2, size.height),
        radius: radius,
      ),
    );
  }

  if (left) {
    cutouts.addOval(
      Rect.fromCircle(center: Offset(0, size.height / 2), radius: radius),
    );
  }

  if (right) {
    cutouts.addOval(
      Rect.fromCircle(
        center: Offset(size.width, size.height / 2),
        radius: radius,
      ),
    );
  }

  Path finalPath = Path.combine(PathOperation.difference, rectPath, cutouts);

  return finalPath;
}