paint method Null safety

  1. @override
void paint(
  1. Canvas canvas,
  2. Rect rect,
  3. {TextDirection? textDirection}
)
override

Paints the border within the given Rect on the given Canvas.

The textDirection argument must be provided and non-null if the border has a text direction dependency (for example if it is expressed in terms of "start" and "end" instead of "left" and "right"). It may be null if the border will not need the text direction to paint itself.

Implementation

@override
void paint(Canvas canvas, Rect rect, { TextDirection? textDirection }) {
  switch (side.style) {
    case BorderStyle.none:
      break;
    case BorderStyle.solid:
      final double width = side.width;
      if (width == 0.0) {
        canvas.drawRRect(borderRadius.resolve(textDirection).toRRect(rect), side.toPaint());
      } else {
        final Paint paint = Paint()
          ..color = side.color;
        if (side.strokeAlign == StrokeAlign.inside) {
          final RRect outer = borderRadius.resolve(textDirection).toRRect(rect);
          final RRect inner = outer.deflate(width);
          canvas.drawDRRect(outer, inner, paint);
        } else {
          final Rect inner;
          final Rect outer;
          if (side.strokeAlign == StrokeAlign.center) {
            inner = rect.deflate(width / 2);
            outer = rect.inflate(width / 2);
          } else {
            inner = rect;
            outer = rect.inflate(width);
          }
          final BorderRadius borderRadiusResolved = borderRadius.resolve(textDirection);
          canvas.drawDRRect(borderRadiusResolved.toRRect(outer), borderRadiusResolved.toRRect(inner), paint);
      }
    }
  }
}