toImage static method

Future<Image?> toImage(
  1. GlobalKey<State<StatefulWidget>> key, {
  2. double pixelRatio = 2.0,
})

Capture as a ui.Image (useful for in-app display / compositing).

Implementation

static Future<ui.Image?> toImage(
  GlobalKey key, {
  double pixelRatio = 2.0,
}) async {
  if (!_isValidPixelRatio(pixelRatio)) return null;
  final boundary =
      key.currentContext?.findRenderObject() as RenderRepaintBoundary?;
  return boundary?.toImage(pixelRatio: pixelRatio);
}