paint method
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) {
final visitedOffsets = <ViewportOffset>{};
final childRo = child;
final editables =
childRo != null ? _findRenderEditables(childRo, offsets: visitedOffsets) : const <RenderEditable>[];
final paragraphs = childRo != null ? _findRenderParagraphs(childRo) : const <RenderParagraph>[];
final selection = _textSelection;
final shouldRecalculate = _rectsDirty || _lastSelection != selection || _cachedSelectionRects.isEmpty;
if (shouldRecalculate) {
final collected = _collectSpoilerRects(
editables: editables,
paragraphs: paragraphs,
selection: selection,
);
_updateCachedRects(collected);
_lastSelection = selection;
_rectsDirty = false;
}
final clipPath = _normalizeClipPath(_onClipPath?.call(size));
if (_enableOverlay) {
super.paint(context, offset);
if (clipPath == null && _onPaint == null && _onAfterPaint == null && _imageFilter == null) {
_syncEditableOffsets(visitedOffsets);
return;
}
if (clipPath != null) {
context.pushClipPath(needsCompositing, offset, paintBounds.shift(offset), clipPath, (c, o) {
_paintOverlayContent(c, o);
});
} else {
_paintOverlayContent(context, offset);
}
_syncEditableOffsets(visitedOffsets);
return;
}
void paintSpoilerLayer(PaintingContext layerContext, Offset layerOffset) {
final spoilerContext = layerContext is SpoilerPaintingContext
? layerContext
: SpoilerPaintingContext(
layer: layer!,
estimatedBounds: paintBounds.shift(layerOffset),
calculateRects: _rectsDirty,
);
Path? particleClipPath;
if (clipPath != null) {
particleClipPath = Path.combine(
PathOperation.difference,
Path()..addRect(Offset.zero & size),
clipPath,
);
}
if (_onPaint != null) {
if (particleClipPath != null) {
spoilerContext.pushClipPath(needsCompositing, layerOffset, paintBounds.shift(layerOffset), particleClipPath,
(c, o) {
_drawParticles(c, o, _onPaint);
});
} else {
_drawParticles(spoilerContext, layerOffset, _onPaint);
}
}
if (clipPath != null) {
spoilerContext.pushClipPath(needsCompositing, layerOffset, paintBounds.shift(layerOffset), clipPath, (c, o) {
_paintChildWithFilter(c, o);
});
} else {
_paintChildWithFilter(spoilerContext, layerOffset);
}
if (_onAfterPaint != null) {
if (particleClipPath != null) {
spoilerContext.pushClipPath(needsCompositing, layerOffset, paintBounds.shift(layerOffset), particleClipPath,
(c, o) {
_drawParticles(c, o, _onAfterPaint);
});
} else {
_drawParticles(spoilerContext, layerOffset, _onAfterPaint);
}
}
}
final rootSpoilerContext = SpoilerPaintingContext(
layer: layer!,
estimatedBounds: paintBounds.shift(offset),
calculateRects: _rectsDirty,
);
paintSpoilerLayer(rootSpoilerContext, offset);
// ignore: invalid_use_of_protected_member
rootSpoilerContext.stopRecordingIfNeeded();
_syncEditableOffsets(visitedOffsets);
}