capture method
Future<CapturedData?>
capture({
- required ScreenshotMode mode,
- bool includeCursor = false,
- int? displayId,
override
Capture a screenshot.
mode: Screenshot capture mode (screen or region)includeCursor: Whether to include the cursor in the screenshotdisplayId: 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.
Implementation
@override
Future<CapturedData?> capture({
required ScreenshotMode mode,
bool includeCursor = false,
int? displayId,
}) async {
try {
// Create request and serialize to map
final CaptureRequest request = CaptureRequest(
mode: mode,
includeCursor: includeCursor,
displayId: displayId,
);
final Map<String, dynamic> arguments = request.toMap();
// Invoke platform method
final Map<Object?, Object?>? result = await methodChannel
.invokeMethod<Map<Object?, Object?>>('capture', arguments);
// Handle null result (cancellation)
if (result == null) {
return null;
}
// Deserialize response
return CapturedData.fromMap(result);
} on PlatformException catch (e) {
// Map PlatformException to ScreenshotException
throw ScreenshotException.fromPlatformException(
code: e.code,
message: e.message,
details: e.details,
);
}
}