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.

Share:
2,396
Chamanhm
Author by

Chamanhm

Updated on December 04, 2022

Comments

  • Chamanhm
    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
    colin almost 6 years
    Great 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
    EduardKieser almost 6 years
    Perhaps you could define an invisable child widget that spans the are that you area interested in and wrap the repaint boundary around that?