toImage method Null safety

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

Creates an image from this picture.

The returned image will be width pixels wide and height pixels high. The picture is rasterized within the 0 (left), 0 (top), width (right), height (bottom) bounds. Content outside these bounds is clipped.

Implementation

Future<Image> toImage(int width, int height) {
  assert(!_disposed);
  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));
      }
    }),
  );
}