-
Notifications
You must be signed in to change notification settings - Fork 149
Description
class WebViewXPageState extends State {
ScreenshotController screenshotController = ScreenshotController();
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Screenshot(controller: screenshotController, child: _buildWebViewX()),
);
}
// Function to capture and share the screenshot of the current screen
Future _captureAndShare(BuildContext context) async {
try {
// Capture the screenshot from the widget
print("Capturing screenshot");
final Uint8List? image = await screenshotController.capture(delay: Duration(milliseconds: 10));
if (image != null) {
print("Image is not null");
// Get the directory to save the image
final directory = await getApplicationDocumentsDirectory();
final imagePath = '${directory.path}/image.png';
// Write the image bytes to a file
await File(imagePath).writeAsBytes(image);
// Share the image using share_plus package
final String body = '''${widget.title}\n\n${widget.shareLink}\n\nvia @AAPWiki Mobile App''';
await Share.shareXFiles(
[XFile(imagePath)],
text: body,
subject: widget.title,
sharePositionOrigin: Rect.fromLTWH(0, 0, 10, 10), // For iPad
);
} else {
print("Image captured is null");
}
} catch (e) {
print("Error: $e");
}
}
Widget _buildWebViewX() {
return Center(child: Text("Testing"));
}
}