captureScreen method
captureScreen captures the current screen and saves in the applicationDirectory. Returns a path where the screenshot is saved. Return type is String
Implementation
Future<String> captureScreen({
required Widget screen,
}) async {
try {
final screenShot = await _screenshotController.captureFromWidget(
MediaQuery(
data: const MediaQueryData(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: Theme.of(context),
home: screen,
),
),
);
final directory = await getApplicationDocumentsDirectory();
final image = File(
'${directory.path}/${DateTime.now().microsecond}${DateTime.now().hashCode}.png');
image.writeAsBytes(screenShot);
return image.path;
} catch (error) {
rethrow;
}
}