capture method

Future<CapturedData?> capture({
  1. required ScreenshotMode mode,
  2. bool includeCursor = false,
  3. int? displayId,
})

Capture a screenshot.

  • mode: Screenshot capture mode (screen or region)
  • includeCursor: Whether to include the cursor in the screenshot
  • displayId: Optional display ID for multi-monitor setups (null = primary display)

Returns CapturedData with image dimensions and PNG-encoded bytes, or null if the operation was cancelled by the user.

Throws ScreenshotException if the operation fails.

Example:

final screenshot = Screenshot.instance;
final data = await screenshot.capture(mode: ScreenshotMode.screen);
if (data != null) {
  print('Captured ${data.width}x${data.height} screenshot');
}

Implementation

Future<CapturedData?> capture({
  required ScreenshotMode mode,
  bool includeCursor = false,
  int? displayId,
}) {
  return ScreenshotPlatform.instance.capture(
    mode: mode,
    includeCursor: includeCursor,
    displayId: displayId,
  );
}