execute method Null safety

Future<void> execute()

Construct an offscreen image of size, and execute warmUpOnCanvas on a canvas associated with that image.

Currently, this has no effect when kIsWeb is true.

Implementation

Future<void> execute() async {
  final ui.PictureRecorder recorder = ui.PictureRecorder();
  final ui.Canvas canvas = ui.Canvas(recorder);
  await warmUpOnCanvas(canvas);
  final ui.Picture picture = recorder.endRecording();
  assert(debugCaptureShaderWarmUpPicture(picture));
  if (!kIsWeb) { // Picture.toImage is not yet implemented on the web.
    final TimelineTask shaderWarmUpTask = TimelineTask();
    shaderWarmUpTask.start('Warm-up shader');
    try {
      final ui.Image image = await picture.toImage(size.width.ceil(), size.height.ceil());
      assert(debugCaptureShaderWarmUpImage(image));
      image.dispose();
    } finally {
      shaderWarmUpTask.finish();
    }
  }
  picture.dispose();
}