Create an image from widget (using package)

Flutter tips Published on

Sometimes you need to save what a Flutter widget looks like as an image, but without actually showing it on the screen. There's a simple way to do this using a package.

How to Create an Image from a Flutter Widget (Without Showing It)

Here are the easy steps:

1. Get the Right Package

First, you need a package that can do this job. A popular one is the screenshot package.

Add the package

You'll need to add it to your project.

Import it in your code

Once added, you can import it like this:

import 'package:screenshot/screenshot.dart';

2. Take the Screenshot

Now that you have the package, you can use it to capture your widget.

Use the ScreenshotController

You'll use a ScreenshotController to manage the capture.

final controller = ScreenshotController();

Capture the widget

Then, you call the captureFromWidget method. You provide the widget you want to capture. You can also set the size and quality using targetSize and pixelRatio.

final imgBytes = controller.captureFromWidget(
  widget,
  targetSize: const Size(320, 520), // Example size
  pixelRatio: 3, // Example quality
);

This imgBytes variable will hold the image data of your widget.

Save 3 months of work

Create your app using our 6 years of making Flutter apps and more than 50+ apps

kickstarter for flutter apps

Frequently Asked Questions

Do I need to show the widget on the screen first?

No, the great thing about this method and the package is that the widget doesn't need to be rendered or visible on the screen.

What package is used for this?

The example shown uses the `screenshot` package.

Can I control the size and quality of the image?

Yes, you can specify the `targetSize` and `pixelRatio` when capturing the widget.

Read more
You may also be interested in
Delegate widget design  blog card image
Delegate widget design
Published on 2025-05-12T09:03:59.853Z
Flutter tip RevenueCat boilerplate  blog card image
Flutter tip RevenueCat boilerplate
Published on 2025-05-12T08:58:02.062Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved