pushColorFilter method

ColorFilterLayer pushColorFilter(
  1. Offset offset,
  2. ColorFilter colorFilter,
  3. PaintingContextCallback painter,
  4. {ColorFilterLayer? oldLayer}

Blend further painting with a color filter.

The offset is the offset to pass to the painter. In particular, it is not an offset applied to the layer itself. Layers conceptually by default have no position or size, though they can transform their contents. For example, an OffsetLayer applies an offset to its children.

The colorFilter argument is the ColorFilter value to use when blending the painting done by painter.

The painter callback will be called while the colorFilter is applied. It is called synchronously during the call to pushColorFilter.

For the oldLayer argument, specify the layer created in the previous frame. This gives the engine more information for performance optimizations. Typically this is the value of RenderObject.layer that a render object creates once, then reuses for all subsequent frames until a layer is no longer needed (e.g. the render object no longer needs compositing) or until the render object changes the type of the layer (e.g. from opacity layer to a clip rect layer).

A RenderObject that uses this function is very likely to require its RenderObject.alwaysNeedsCompositing property to return true. That informs ancestor render objects that this render object will include a composited layer, which, for example, causes them to use composited clips.


ColorFilterLayer pushColorFilter(Offset offset, ColorFilter colorFilter, PaintingContextCallback painter, { ColorFilterLayer? oldLayer }) {
  final ColorFilterLayer layer = oldLayer ?? ColorFilterLayer();
  layer.colorFilter = colorFilter;
  pushLayer(layer, painter, offset);
  return layer;