Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Taking a screenshot of a specific Widget in Flutter?

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?

like image 346
Chamanhm Avatar asked Apr 25 '18 23:04

Chamanhm


1 Answers

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.

like image 56
EduardKieser Avatar answered Oct 03 '22 06:10

EduardKieser