The Flutter Widget Previewer

Flutter tips Published on

What is the Flutter Widget Previewer?

Flutter 3.35 brought us a fantastic new tool: the Widget Previewer! This feature lets you see how your widgets look and behave without needing to run your entire application. It's a huge time-saver for developers. Ready to give it a try? Here's how to use it.

Getting Started with the Widget Previewer

Step 1: Run the Command

First, open your terminal and navigate to the root of your Flutter project. Then, run this simple command:

flutter widget-preview start

This command kicks off the preview server, allowing you to see your widgets in action.

Step 2: Add the Annotation

Next, you need to tell Flutter which widget you want to preview. You do this by adding a special annotation, @Preview, to your widget's factory method or function. Look at this example:

(name: 'Primary Button Large')
factory PrimaryButton.largePreview() {
  return PrimaryButton(text: "text", onTap: () {});
}
What You Can Preview

The @Preview annotation works with a few specific types of code:

Providing a Theme

The @Preview annotation also allows you to include a theme. While it might not work perfectly with all custom themes right away, a great workaround is to directly embed your widget inside a MaterialApp with your chosen theme. This ensures your widget looks just right in the preview.

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

What is the Flutter Widget Previewer?

It's a new feature in Flutter 3.35 that lets you quickly preview individual widgets without needing to render or launch your entire Flutter application. It saves a lot of time during development.

Which Flutter version introduced the Widget Previewer?

The Widget Previewer was introduced in Flutter version 3.35.

How do I start the Widget Previewer in my project?

You start it by opening your terminal, going to your project's root folder, and running the command `flutter widget-preview start`.

How do I mark a widget to be previewed?

You use the `@Preview` annotation on a top-level function, a static method, or a public widget constructor/factory that returns a Widget or WidgetBuilder.

Can I use a custom theme with the Widget Previewer?

Yes, you can. A good way to ensure your custom theme applies is to embed your widget directly within a `MaterialApp` that uses your custom theme for the preview.

Read more
You may also be interested in
Go Beyond Material: Add Custom Colors in your Flutter Theme  blog card image
Go Beyond Material: Add Custom Colors in your Flutter Theme
Published on 2025-05-12T08:49:42.146Z
Extension types  blog card image
Extension types
Published on 2025-11-28T16:56:59.637Z
ApparenceKit is a flutter template generator tool by Apparence.io © 2025.
All rights reserved