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) {
  // cut the avatar by the previous avatar
  // avatars are rounded rectangles

  var prevAvatarSize = previousAvatarSize;

  double widthDiff = size.width - prevAvatarSize;
  double heightDiff = size.height - prevAvatarSize;

  // align both at center first
  double left = (widthDiff / 2);
  double top = (heightDiff / 2);

  left += size.width * alignment.x;
  top += size.height * alignment.y;

  Path path = Path();
  path.fillType = PathFillType.evenOdd;
  path.addRect(Rect.fromLTWH(0, 0, size.width, size.height));
  if (borderRadius > 0) {
    path.addRRect(
      RRect.fromRectAndRadius(
        Rect.fromLTWH(
          left - gap,
          top - gap,
          prevAvatarSize + gap * 2,
          prevAvatarSize + gap * 2,
        ),
        Radius.circular(borderRadius + gap * 2),
      ),
    );
  } else {
    path.addRect(
      Rect.fromLTWH(
        left - gap,
        top - gap,
        prevAvatarSize + gap * 2,
        prevAvatarSize + gap * 2,
      ),
    );
  }
  return path;
}