Taking a screenshot of a specific Widget in Flutter?
2,396
I think this might be what you are looking for: https://docs.flutter.io/flutter/rendering/RenderRepaintBoundary/toImage.html
Basically you wrap your widget in a RepaintBoundary
. Supply the RepaintBoundary
with a key, which we can call boundaryKey
.
You can then do:
RenderRepaintBoundary boundary = boundaryKey.currentContext.findRenderObject();
and then do ui.Image image = await boundary.toImage();
to create an image that you can then use to create a png or whatever you want.
Author by
Chamanhm
Updated on December 04, 2022Comments
-
Chamanhm over 1 year
I have a widget with an image and some information that I would like the user to be able to save and share as an image.
Does anyone know how to accomplish this without specifically telling the user to physically take the screenshot?
-
colin almost 6 yearsGreat solution ! I'm wondering if it is possible to capture only parts of the Widgets ? Because only a portion of the widget is what I needed.
-
EduardKieser almost 6 yearsPerhaps you could define an invisable child widget that spans the are that you area interested in and wrap the repaint boundary around that?