SePröbläm
SePröbläm

Reputation: 5739

Flutter: How to generate screenshots in arbitrary resolutions?

In Flutter, how do you get a screenshot for an arbitrary screen resolution? I.e. for a screen resolution that's different from the resolution the app is running in?

Is there a way to tell the Flutter engine to paint a single frame into a buffer with a specific resolution?

What I'm trying to accomplish is to generate the screenshots for the various app stores from within the app, but without scaling and cropping screenshots that were taken for different devices/resolutions.

How would you tackle that requirement?

Any advise is welcome, Thank you!

Upvotes: 1

Views: 159

Answers (1)

Gagan Kumar
Gagan Kumar

Reputation: 123

if you are talking about taking a screenshot of a particular widget and saving it the you have to use renderrepaint boundry with key . dependencies - path provider Image gallery saver ..

  takeScreenshot(BuildContext context,GlobalKey _key,String slug) async {
      RenderRepaintBoundary boundary = _key.currentContext.findRenderObject();
      ui.Image image = await boundary.toImage(pixelRatio: 3.0);
      final snackBar = SnackBar(content: Text("Image saved to gallery"));
      ScaffoldMessenger.of(context).showSnackBar(snackBar);
    
      final directory = (await getApplicationDocumentsDirectory()).path;
      ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
      final result = await ImageGallerySaver.saveImage(
          byteData.buffer.asUint8List(),
          name: "name.jpg");
    }

Upvotes: 1

Related Questions