paint method

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

Paint this render object into the given context at the given offset.

Subclasses should override this method to provide a visual appearance for themselves. The render object's local coordinate system is axis-aligned with the coordinate system of the context's canvas and the render object's local origin (i.e, x=0 and y=0) is placed at the given offset in the context's canvas.

Do not call this function directly. If you wish to paint yourself, call markNeedsPaint instead to schedule a call to this function. If you wish to paint one of your children, call PaintingContext.paintChild on the given context.

When painting one of your children (via a paint child function on the given context), the current canvas held by the context might change because draw operations before and after painting children might need to be recorded on separate compositing layers.

Implementation

@override
void paint(PaintingContext context, Offset offset) {
  if (_firstNonPinnedCell == null &&
      _lastPinnedRow == null &&
      _lastPinnedColumn == null) {
    assert(_lastNonPinnedCell == null);
    return;
  }

  // Subclasses of RenderTwoDimensionalViewport will typically use
  // firstChild to traverse children in a standard paint order that
  // follows row or column major ordering. Here is slightly different
  // as we break the cells up into 4 main paint passes to clip for overlap.

  if (_firstNonPinnedCell != null) {
    // Paint all visible un-pinned cells
    assert(_lastNonPinnedCell != null);
    _clipCellsHandle.layer = context.pushClipRect(
      needsCompositing,
      offset,
      Rect.fromLTWH(
        axisDirectionIsReversed(horizontalAxisDirection)
            ? 0.0
            : _pinnedColumnsExtent,
        axisDirectionIsReversed(verticalAxisDirection)
            ? 0.0
            : _pinnedRowsExtent,
        viewportDimension.width - _pinnedColumnsExtent,
        viewportDimension.height - _pinnedRowsExtent,
      ),
      (PaintingContext context, Offset offset) {
        _paintCells(
          context: context,
          offset: offset,
          leadingVicinity: _firstNonPinnedCell!,
          trailingVicinity: _lastNonPinnedCell!,
        );
      },
      clipBehavior: clipBehavior,
      oldLayer: _clipCellsHandle.layer,
    );
  } else {
    _clipCellsHandle.layer = null;
  }

  if (_lastPinnedColumn != null && _firstNonPinnedRow != null) {
    // Paint all visible pinned column cells that do not intersect with pinned
    // row cells.
    _clipPinnedColumnsHandle.layer = context.pushClipRect(
      needsCompositing,
      offset,
      Rect.fromLTWH(
        axisDirectionIsReversed(horizontalAxisDirection)
            ? viewportDimension.width - _pinnedColumnsExtent
            : 0.0,
        axisDirectionIsReversed(verticalAxisDirection)
            ? 0.0
            : _pinnedRowsExtent,
        _pinnedColumnsExtent,
        viewportDimension.height - _pinnedRowsExtent,
      ),
      (PaintingContext context, Offset offset) {
        _paintCells(
          context: context,
          offset: offset,
          leadingVicinity: TableVicinity(column: 0, row: _firstNonPinnedRow!),
          trailingVicinity: TableVicinity(
              column: _lastPinnedColumn!, row: _lastNonPinnedRow!),
        );
      },
      clipBehavior: clipBehavior,
      oldLayer: _clipPinnedColumnsHandle.layer,
    );
  } else {
    _clipPinnedColumnsHandle.layer = null;
  }

  if (_lastPinnedRow != null && _firstNonPinnedColumn != null) {
    // Paint all visible pinned row cells that do not intersect with pinned
    // column cells.
    _clipPinnedRowsHandle.layer = context.pushClipRect(
      needsCompositing,
      offset,
      Rect.fromLTWH(
        axisDirectionIsReversed(horizontalAxisDirection)
            ? 0.0
            : _pinnedColumnsExtent,
        axisDirectionIsReversed(verticalAxisDirection)
            ? viewportDimension.height - _pinnedRowsExtent
            : 0.0,
        viewportDimension.width - _pinnedColumnsExtent,
        _pinnedRowsExtent,
      ),
      (PaintingContext context, Offset offset) {
        _paintCells(
          context: context,
          offset: offset,
          leadingVicinity:
              TableVicinity(column: _firstNonPinnedColumn!, row: 0),
          trailingVicinity: TableVicinity(
              column: _lastNonPinnedColumn!, row: _lastPinnedRow!),
        );
      },
      clipBehavior: clipBehavior,
      oldLayer: _clipPinnedRowsHandle.layer,
    );
  } else {
    _clipPinnedRowsHandle.layer = null;
  }

  if (_lastPinnedRow != null && _lastPinnedColumn != null) {
    // Paint remaining visible pinned cells that represent the intersection of
    // both pinned rows and columns.
    _paintCells(
      context: context,
      offset: offset,
      leadingVicinity: TableVicinity.zero,
      trailingVicinity:
          TableVicinity(column: _lastPinnedColumn!, row: _lastPinnedRow!),
    );
  }
}