pushOpacity method

OpacityLayer pushOpacity (Offset offset, int alpha, PaintingContextCallback painter, { OpacityLayer oldLayer })

Blend further painting with an alpha value.

  • offset is the offset from the origin of the canvas' coordinate system to the origin of the caller's coordinate system.
  • alpha 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.
  • painter is a callback that will paint with the alpha applied. This function calls the painter synchronously. null

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;
}