Canvas constructor Null safety

Canvas(
  1. PictureRecorder recorder,
  2. [Rect? cullRect]
)

Creates a canvas for recording graphical operations into the given picture recorder.

Graphical operations that affect pixels entirely outside the given cullRect might be discarded by the implementation. However, the implementation might draw outside these bounds if, for example, a command draws partially inside and outside the cullRect. To ensure that pixels outside a given region are discarded, consider using a clipRect. The cullRect is optional; by default, all operations are kept.

To end the recording, call PictureRecorder.endRecording on the given recorder.

Implementation

@pragma('vm:entry-point')
Canvas(PictureRecorder recorder, [ Rect? cullRect ]) : assert(recorder != null) {
  if (recorder.isRecording) {
    throw ArgumentError('"recorder" must not already be associated with another Canvas.');
  }
  _recorder = recorder;
  _recorder!._canvas = this;
  cullRect ??= Rect.largest;
  _constructor(recorder, cullRect.left, cullRect.top, cullRect.right, cullRect.bottom);
}