takeScreenShotAndShare static method
Future
takeScreenShotAndShare(
- BuildContext context, {
- required ScreenshotController controller,
- required String subject,
})
Implementation
static Future takeScreenShotAndShare(BuildContext context,
{required ScreenshotController controller,
required String subject}) async {
final snackBar = HubbleSnackBar.of(context);
final directory = (await getApplicationDocumentsDirectory()).path;
await controller
.capture(delay: const Duration(milliseconds: 10), pixelRatio: 2.0)
.then((image) async {
if (image != null) {
final file = File('$directory/screenshot.png');
file.writeAsBytesSync(image.toList());
await Share.shareXFiles(
[XFile(file.path)],
subject: subject,
);
}
}).catchError((error) {
snackBar.error(
title: 'Something went wrong',
message: 'Could not take screenshot',
);
});
}