paintSnapshot abstract method

void paintSnapshot(
  1. PaintingContext context,
  2. Offset offset,
  3. Size size,
  4. Image image,
  5. Size sourceSize,
  6. double pixelRatio,
)

Called whenever the image that represents a SnapshotWidgets child should be painted.

The image is rasterized at the physical pixel resolution and should be scaled down by pixelRatio to account for device independent pixels.

The following method shows how the default implementation of the delegate used by the SnapshotPainter paints the snapshot. This must account for the fact that the image width and height will be given in physical pixels, while the image must be painted with device independent pixels. That is, the width and height of the image is the widget and height of the provided size, multiplied by the pixelRatio. In addition, the actual size of the scene captured by the image is not image.width or image.height, but indeed sourceSize, because the former is a rounded inaccurate integer:
link
void paint(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio) {
  final Rect src = Rect.fromLTWH(0, 0, sourceSize.width, sourceSize.height);
  final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
  final Paint paint = Paint()
    ..filterQuality = FilterQuality.medium;
  context.canvas.drawImageRect(image, src, dst, paint);
}

Implementation

void paintSnapshot(PaintingContext context, Offset offset, Size size, ui.Image image, Size sourceSize, double pixelRatio);