paintLayer method

  1. @Deprecated('Use layers.push instead')
void paintLayer(
  1. ContainerLayer layer, {
  2. VoidCallback? painter,
  3. Offset? offset,
  4. Rect? debugBounds,
})

Paints a ContainerLayer compositing layer in the current painting context with an optional painter callback, this should only be called in paintChildren.

This is useful if you wanted to apply filters to your children, for example:

paintLayer(
  OpacityLayer(alpha: 127),
  painter: getChild(#title).paint,
);

Implementation

@Deprecated('Use layers.push instead')
void paintLayer(
  ContainerLayer layer, {
  VoidCallback? painter,
  Offset? offset,
  Rect? debugBounds,
}) {
  final render = this.render;
  paintingContext.pushLayer(layer, (context, offset) {
    final lastContext = render.paintingContext;
    final lastOffset = render.paintOffset;
    render.paintingContext = context;
    render.paintOffset = lastOffset;
    if (painter != null) {
      painter();
    }
    render.paintingContext = lastContext;
    render.paintOffset = lastOffset;
  }, offset ?? render.paintOffset!, childPaintBounds: debugBounds);
}