'Preview widget screenshot flutter
Hello guys I am new to flutter.
How can I take a screenshot from a widget, preview it to a new page and decide if I would like to save it in the gallery or not?
Here is my code
takeScreenShot(BuildContext context) async {
final path= join((await getTemporaryDirectory()).path,"${DateTime.now()}.png");
RenderRepaintBoundary boundary =
_globalKey.currentContext.findRenderObject();
var image = await boundary.toImage();
var byteData = await image.toByteData(format: ImageByteFormat.png);
var pngBytes = byteData.buffer.asUint8List();
Navigator.push(context, MaterialPageRoute(builder: (builder)=>ScreenshotViewPage(path: path,)));
}
The global key is added to the root widget.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
