getClipPath method Null safety

  1. @override
Path getClipPath(
  1. Rect rect,
  2. TextDirection textDirection
)
override

Returns a closed Path that describes the outer edge of this decoration.

The default implementation throws. Subclasses must override this implementation to describe the clip path that should be applied to the decoration when it is used in a Container with an explicit Clip behavior.

See also:

Implementation

@override
Path getClipPath(Rect rect, TextDirection textDirection) {
  switch (shape) {
    case BoxShape.circle:
      final Offset center = rect.center;
      final double radius = rect.shortestSide / 2.0;
      final Rect square = Rect.fromCircle(center: center, radius: radius);
      return Path()..addOval(square);
    case BoxShape.rectangle:
      if (borderRadius != null)
        return Path()..addRRect(borderRadius!.resolve(textDirection).toRRect(rect));
      return Path()..addRect(rect);
  }
}