capture static method

Future<Screenshot> capture({
  1. double? pixelRatio,
  2. bool settle = true,
  3. String? locale,
  4. String? theme,
})

Captures the whole screen, dialogs and sheets included.

pixelRatio defaults to the device's, so the PNG has the screen's native resolution. The capture waits for the next frame first, so anything just changed is drawn; pass settle: false when a frame has just been drawn.

With locale (a language code) or theme (a theme id), the screen is shown that way for the capture and put back straight after, keeping the page and its state. See ScreenshotLook.

In an app built with NyApp.materialApp, or with a ScreenshotRoot in its MaterialApp.builder, the capture holds exactly the app's pages. Other apps get the whole Flutter view.

Implementation

static Future<Screenshot> capture({
  double? pixelRatio,
  bool settle = true,
  String? locale,
  String? theme,
}) async {
  if (locale != null || theme != null) {
    return _inLook(
      locale,
      theme,
      () => capture(pixelRatio: pixelRatio, settle: false),
    );
  }
  return _hidingPrivate(settle, () {
    final RenderObject? boundary = rootKey.currentContext?.findRenderObject();
    if (boundary is RenderRepaintBoundary && boundary.attached) {
      return _fromBoundary(boundary, pixelRatio);
    }
    return _fromView(pixelRatio);
  });
}