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 }) {
  if (rect.isEmpty) {
    return;
  }
  switch (side.style) {
    case BorderStyle.none:
      break;
    case BorderStyle.solid:
      final RRect borderRect = borderRadius.resolve(textDirection).toRRect(rect);
      final RRect adjustedRect;
      switch (side.strokeAlign) {
        case StrokeAlign.inside:
          adjustedRect = borderRect;
          break;
        case StrokeAlign.center:
          adjustedRect = borderRect.inflate(side.width / 2);
          break;
        case StrokeAlign.outside:
          adjustedRect = borderRect.inflate(side.width);
          break;
      }
      final Path path = _getPath(adjustedRect)
        ..addPath(getInnerPath(rect, textDirection: textDirection), Offset.zero);
      canvas.drawPath(path, side.toPaint());
      break;
  }
}