pushOpacity method

OpacityLayer pushOpacity(
  1. Offset offset,
  2. int alpha,
  3. PaintingContextCallback painter,
  4. {OpacityLayer? oldLayer}
)

Blend further painting with an alpha value.

The offset argument indicates an offset to apply to all the children (the rendering created by painter).

The alpha argument is the alpha value to use when blending the painting done by painter. An alpha value of 0 means the painting is fully transparent and an alpha value of 255 means the painting is fully opaque.

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

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.

Implementation

OpacityLayer pushOpacity(Offset offset, int alpha, PaintingContextCallback painter, { OpacityLayer? oldLayer }) {
  final OpacityLayer layer = oldLayer ?? OpacityLayer();
  layer
    ..alpha = alpha
    ..offset = offset;
  pushLayer(layer, painter, Offset.zero);
  return layer;
}