Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot elements not rendered on screen? #25

Closed
vedantrathore opened this issue Sep 29, 2020 · 6 comments
Closed

Screenshot elements not rendered on screen? #25

vedantrathore opened this issue Sep 29, 2020 · 6 comments

Comments

@vedantrathore
Copy link

Hello @SachinGanesh thanks for the package. I'm trying to screenshot a part of the widget tree but I need to add some custom widgets to the screenshot, those widgets in the screenshot should not be shown on the screen. Is there a way to achieve this using this package?

@vedantrathore
Copy link
Author

Any update ?

@Sammius
Copy link

Sammius commented Mar 1, 2021

It would be very helpful for me too!

@bdlukaa
Copy link

bdlukaa commented Mar 1, 2021

It's not possible because this package uses a RepaintBoundary under the hood, so that means it can only take screenshot of the widgets that are rendered. What you can do is add the widgets to the screen, take a screenshot, and then remove them:

setState(() => widgetsVisible = true);
await takeScreenshot();
setState(() => widgetsVisible = false);

You can use something like overlay or dialog to hide the screen while the screenshot is happening!

@Sammius
Copy link

Sammius commented Mar 14, 2021

I am currently using the functions from here. It also uses RepaintBoundary, but no real repaints are required. Maybe something similar can be applied here.

@ritheshSalyan
Copy link
Collaborator

Currently Screenshot support capturing of non rendered elements. You can make use of captureFromWidget function like shown below

  screenshotController
                    .captureFromWidget(Container(
                        padding: const EdgeInsets.all(30.0),
                        decoration: BoxDecoration(
                          border:
                              Border.all(color: Colors.blueAccent, width: 5.0),
                          color: Colors.redAccent,
                        ),
                        child: Text("This is an invisible widget")))
                    .then((capturedImage) {
                  ShowCapturedWidget(context, capturedImage);
                });

@daybson
Copy link

daybson commented Oct 12, 2021

Currently Screenshot support capturing of non rendered elements. You can make use of captureFromWidget function like shown below

  screenshotController
                    .captureFromWidget(Container(
                        padding: const EdgeInsets.all(30.0),
                        decoration: BoxDecoration(
                          border:
                              Border.all(color: Colors.blueAccent, width: 5.0),
                          color: Colors.redAccent,
                        ),
                        child: Text("This is an invisible widget")))
                    .then((capturedImage) {
                  ShowCapturedWidget(context, capturedImage);
                });

How do I trigger the captureFromWidget from a method, if the wifget to be captured is the Scaffold? There's my Listview with some elements outside view, and I want them on the screen shot too.

@override
  Widget build(BuildContext context) {
    b = build2(context);
    return b;
  }

void printScreen() async {
    screenshotController
        .captureFromWidget(Container(
            padding: const EdgeInsets.all(30.0),
            decoration: BoxDecoration(
              border: Border.all(color: Colors.blueAccent, width: 5.0),
              color: Colors.redAccent,
            ),
            child: b))
        .then((image) async {
      final directory = (await getTemporaryDirectory()).path;
      File imgFile =
          new File('$directory/${controller.ficha.value.nome}_screenshot.png');
      await imgFile.writeAsBytes(image);
      Share.shareFiles(['${imgFile.path}'],
          text: 'Personagem ${controller.ficha.value.nome}');
    });
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants