paintNonUniformBorder static method

void paintNonUniformBorder(
  1. Canvas canvas,
  2. Rect rect, {
  3. required BorderRadius? borderRadius,
  4. required TextDirection? textDirection,
  5. BoxShape shape = BoxShape.rectangle,
  6. BorderSide top = BorderSide.none,
  7. BorderSide right = BorderSide.none,
  8. BorderSide bottom = BorderSide.none,
  9. BorderSide left = BorderSide.none,
  10. required Color color,
})

Paints a Border with different widths, styles and strokeAligns, on any borderRadius while using a single color.

See also:

  • paintBorder, which supports multiple colors but not borderRadius.
  • paint, which calls this method.

Implementation

static void paintNonUniformBorder(
  Canvas canvas,
  Rect rect, {
  required BorderRadius? borderRadius,
  required TextDirection? textDirection,
  BoxShape shape = BoxShape.rectangle,
  BorderSide top = BorderSide.none,
  BorderSide right = BorderSide.none,
  BorderSide bottom = BorderSide.none,
  BorderSide left = BorderSide.none,
  required Color color,
}) {
  final RRect borderRect;
  switch (shape) {
    case BoxShape.rectangle:
      borderRect = (borderRadius ?? BorderRadius.zero)
          .resolve(textDirection)
          .toRRect(rect);
    case BoxShape.circle:
      assert(borderRadius == null, 'A borderRadius cannot be given when shape is a BoxShape.circle.');
      borderRect = RRect.fromRectAndRadius(
        Rect.fromCircle(center: rect.center, radius: rect.shortestSide / 2.0),
        Radius.circular(rect.width),
      );
  }
  final Paint paint = Paint()..color = color;
  final RRect inner = _deflateRRect(borderRect, EdgeInsets.fromLTRB(left.strokeInset, top.strokeInset, right.strokeInset, bottom.strokeInset));
  final RRect outer = _inflateRRect(borderRect, EdgeInsets.fromLTRB(left.strokeOutset, top.strokeOutset, right.strokeOutset, bottom.strokeOutset));
  canvas.drawDRRect(outer, inner, paint);
}