I’m using the ScreenCapturer package in Flutter to capture screenshots on Windows. However, the method _handleClickCapture returns null instead of capturing the screenshot. Here is my code:
void _handleClickCapture(CaptureMode mode, BuildContext context, {
int displayNumber = 1,
}) async {
Directory directory = await getApplicationDocumentsDirectory();
String imageName =
'Screenshot-${DateTime.now().millisecondsSinceEpoch}.png';
String imagePath =
'${directory.path}/screen_capturer_example/Screenshots/$imageName';
_lastCapturedData = await ScreenCapturer.instance.capture(
mode: mode,
imagePath: imagePath,
silent: true,
);
if (_lastCapturedData != null) {
// ignore: avoid_print
// print(_lastCapturedData!.toJson());
} else {`your text``your text`
// ignore: avoid_print
print('User canceled capture');
}
setState(() {});
}
I tried setting up the necessary parameters and requirements for the library on Windows. The logs initially return the correct path for the created image, but then I get messages like “Image file does not exist” and other similar logs.
SaveScreenBug— Captured image path: C:UsersAdminAppDataLocalTemptemp_screenshots/Screenshots/Screenshot-1718193689806.png
SaveScreenBug— Last image path added to CustomStorage
SaveScreenBug— Capture data: [null, false]
SaveScreenBug— Captured image path is NULL
Oleh Evdoshenko is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.