toImage method Null safety

Future<Image> toImage(
  1. int width,
  2. int height
)

Creates a raster image representation of the current state of the scene. This is a slow operation that is performed on a background thread.

Callers must dispose the Image when they are done with it. If the result will be shared with other methods or classes, Image.clone should be used and each handle created must be disposed.

Implementation

Future<Image> toImage(int width, int height) {
  if (width <= 0 || height <= 0) {
    throw Exception('Invalid image dimensions.');
  }
  return _futurize((_Callback<Image?> callback) => _toImage(width, height, (_Image? image) {
      if (image == null) {
        callback(null);
      } else {
        callback(Image._(image, image.width, image.height));
      }
    }),
  );
}