paint method

  1. @override
void paint(
  1. PaintingContext context,
  2. Offset offset
)
override

Default paint implementation.

RenderBox paints no self-content; it forwards painting to its RenderBox children. Subclasses override to draw their own content.

Implementation

@override
void paint(PaintingContext context, Offset offset) {
  if (_columnWidths.isEmpty || size.width <= 0 || size.height <= 0) return;
  final origin = offset + Offset(x, y);
  context.canvas.save();
  try {
    context.canvas.clipRect(origin & size);
    final columnStarts = _columnStarts();
    final rowStarts = _rowStarts();
    if (_showBorders) {
      _paintBorders(context, origin, columnStarts, rowStarts);
    }
    for (final cell in _cells) {
      final x = columnStarts[cell.column] + _cellPaddingX;
      final y = rowStarts[cell.row] + _cellPaddingY;
      final localSelection = _localSelection(cell);
      context.canvas.drawTextLayout(
        cell.layout,
        Offset(origin.dx + x, origin.dy + y),
        sourceRect: Rect.fromLTWH(
          0,
          0,
          _columnWidths[cell.column],
          _rowHeights[cell.row] - _cellPaddingY * 2,
        ),
        selection: localSelection,
      );
    }
  } finally {
    context.canvas.restore();
  }
}