takeScreenshot method
Implementation
Future<MediaEntity?> takeScreenshot() async {
try {
final boundary = _playgroundKey.currentContext?.findRenderObject()
as RenderRepaintBoundary?;
if (boundary != null) {
final image = await boundary.toImage();
final byteData = await image.toByteData(format: ImageByteFormat.png);
final data = byteData!.buffer.asUint8List();
final entity = await PhotoManager.editor.saveImage(data, title: '');
await SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
overlays: SystemUiOverlay.values);
return MediaEntity(entity: entity!, bytes: data);
}
} catch (e) {
log('Exception occurred while capturing picture : $e');
}
return null;
}