Screenshot class

A PNG of the app's screen, or of one ScreenshotArea.

// The whole screen as the user sees it, dialogs and sheets included.
final Screenshot shot = await Screenshot.capture();
await shot.store('reports/checkout.png');

// One part of the screen, wrapped in a ScreenshotArea.
final Screenshot receipt = await Screenshot.area('receipt');
await receipt.store('order-1042.png', disk: 'public');

Captures work in every build mode, so they can power app features like sharing a receipt or attaching the screen to a bug report. Metro's screenshot command uses the same code.

Constructors

Screenshot({required Uint8List bytes, required int width, required int height})
Creates a screenshot from bytes, a PNG of width by height physical pixels.
const

Properties

bytes → Uint8List
The PNG.
final
hashCode → int
The hash code for this object.
no setterinherited
height → int
The height in physical pixels.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
width → int
The width in physical pixels.
final

Methods

forStore(ScreenshotStore store, {bool frame = false, String? caption, Color? background}) → Future<Screenshot>
This screenshot at the exact size store asks for.
framed({String? caption, Color? background}) → Future<Screenshot>
This screenshot drawn in a plain phone outline on background, under caption, at its own size.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
store(String path, {String? disk}) → Future<String>
Saves the PNG to path on disk, or on the default disk, and returns path.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

areas → List<String>
The names of the ScreenshotAreas on screen.
no setter
overlayKey → GlobalKey<OverlayState>
The overlay above rootKey, for things drawn over the app that stay out of captures, like a playbook's finger and captions.
final
rootKey → GlobalKey<State<StatefulWidget>>
The boundary around the app's screen, which NyApp places in its MaterialApp.builder through ScreenshotRoot.
final

Static Methods

area(String name, {double? pixelRatio, bool settle = true, String? locale, String? theme}) → Future<Screenshot>
Captures the ScreenshotArea called name.
capture({double? pixelRatio, bool settle = true, String? locale, String? theme}) → Future<Screenshot>
Captures the whole screen, dialogs and sheets included.
settleAnimations({Duration timeout = const Duration(seconds: 1)}) → Future<void>
Waits for the next frame, then for running animations, like a theme fading in, to finish, for at most timeout.
widget(Widget child, {Size? size, double? pixelRatio, BuildContext? context, Duration delay = Duration.zero}) → Future<Screenshot>
Captures child without showing it, e.g. a share card built just for the image.

Constants

allLocales → const List<String>
Every language the app bundles a file for, for a playbook's screenshot('cart', locales: Screenshot.allLocales).
allThemes → const List<String>
Every registered theme, for a playbook's screenshot('cart', themes: Screenshot.allThemes).