createPicture method

Picture createPicture([
  1. void prePaintCallback(
    1. Canvas
    )?,
  2. void postPaintCallback(
    1. Canvas
    )?
])

Creates a picture of the current state of the DisplayObject. To ensure the "original" form, call before applying any transformations (x, y, scale, etc).

Optionally accepts prePaintCallback and postPaintCallback functions that allow to customize the painting process.

Implementation

ui.Picture createPicture(
    [void Function(ui.Canvas)? prePaintCallback,
    void Function(ui.Canvas)? postPaintCallback]) {
  final r = ui.PictureRecorder();
  final c = ui.Canvas(r);
  prePaintCallback?.call(c);
  paint(c);
  postPaintCallback?.call(c);
  return r.endRecording();
}