Skip to content
Agentmart
Submit a tool

flutter-add-widget-preview

Use when configuring widget previews in Flutter development, testing visual component variations, or isolating widget UI states.

Skill by dhruvanbhalara

IndexedMIT★ 30
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/dhruvanbhalara-flutter-add-widget-preview

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Use when configuring widget previews in Flutter development, testing visual component variations, or isolating widget UI states.

Use cases: design, frontend, testing

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md and code. Checked Oct 26, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/flutter-add-widget-preview

What's inside

Skill name
flutter-add-widget-preview
Description
Use when configuring widget previews in Flutter development, testing visual component variations, or isolating widget UI states.
License
MIT
Metadata
category: ui · languages: dart · platforms: flutter
Instructions
163 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

## Contents
- [Preview Guidelines](#preview-guidelines)
- [Handling Limitations](#handling-limitations)
- [IDE and CLI Integration](#ide-and-cli-integration)
- [Custom Annotations](#custom-annotations)
- [Workflow: Adding a Widget Preview](#workflow-adding-a-widget-preview)
- [Examples](#examples)

## Preview Guidelines

Use the Flutter Widget Previewer to render widgets in real-time, isolated from the full application context.

-   **Target Elements**: Apply the `@Preview` annotation to:
    -   Top-level functions returning `Widget`
    -   Static methods within a class returning `Widget`
    -   Public widget constructors/factories with no required arguments
-   **Import**: Always import `package:flutter/widget_previews.dart`.
-   **Multiple Configurations**: Apply multiple `@Preview` annotations to a single target for multiple preview instances (e.g., light/dark mode).
-   **Naming**: Use `name` and `group` parameters for organized preview panels.
-   **Sizing**: Apply explicit constraints using the `size` parameter if the widget is unconstrained (the previewer defaults to approximately half the viewport).

## Handling Limitations

The Widget Previewer runs in a **web environment**. Adhere to these constraints:

| Limitation | Impact | Workaround |
|---|---|---|
| No `dart:io` | File system, sockets unavailable | Use conditional imports to mock |
| No `dart:ffi` | Native code won't execute | Stub native calls in preview mode |
| Asset paths | `dart:ui` `fromAsset` requires package paths | Use `packages/my_package/assets/...` |
| Callbacks | Must be public and constant | No closures in annotation params |
| Unconstrained widgets | May render incorrectly | Set `size` parameter in `@Preview` |

## IDE and CLI Integration

### IDE (Android Studio, IntelliJ, VS Code with Flutter 3.38+)
1.  Launch the IDE. The Widget Previewer starts automatically.
2.  Open the **"Flutter Widget Preview"** tab in the sidebar.
3.  Toggle **"Filter previews by selected file"** at the bottom left to view previews outside the active file.

### Command Line
```bash
flutter widget-preview start
```
Opens a Chrome environment with live previews.

### Feedback Loop
1.  Modify the widget code or preview configuration.
2.  Observe the automatic update in the Widget Previewer.
3.  If global state was modified → click global hot restart (bottom right).
4.  If only local widget state needs resetting → click individual hot restart on the preview card.
5.  Review errors in the IDE/CLI console → fix → repeat.

## Custom Annotations

### Extending Preview
Create reusable preview configurations by extending the `Preview` class:
```dart
import 'package:flutter/widget_previews.dart';
import 'package:flutter/material.dart';

final class ThemedPreview extends Preview {
  const ThemedPreview({super.name, super.group});

  PreviewThemeData _themeBuilder() {
    return PreviewThemeData(
      materialLight: ThemeData.light(),
      materialDark: ThemeData.dark(),
    );
  }

  @override
  Preview transform() {
    final originalPreview = super.transform();
    final builder = originalPreview.toBuilder()
      ..name = 'Themed - ${originalPreview.name}'
      ..theme = _themeBuilder;
    return builder.toPreview();
  }
}

@ThemedPreview(name: 'Primary Button')
Widget primaryButton() => const ElevatedButton(onPressed: null, child: Text('Click'));
```

### MultiPreview for Brightness Variants
```dart
final class MultiBrightnessPreview extends MultiPreview {
  const MultiBrightnessPreview({required this.name});
  final String name;

  @override
  List<Preview> get previews => const [
    Preview(brightness: Brightness.light),
    Preview(brightness: Brightness.dark),
  ];

  @override
  List<Preview> transform() {
    return super.transform().map((preview) {
      final builder = preview.toBuilder()
        ..group = 'Brightness'
        ..name = '$name - ${preview.brightness!.name}';
      return builder.toPreview();
    }).toList();
  }
}

@MultiBrightnessPreview(name: 'User Card')
Widget userCard() => const Card(
  child: Padding(padding: EdgeInsets.all(16), child: Text('John Doe')),
);
```

## Workflow: Adding a Widget Preview

### Task Progress
- [ ] **Step 1**: Import `package:flutter/widget_previews.dart`.
- [ ] **Step 2**: Identify valid target (top-level function, static method, or no-arg constructor).

From dhruvanbhalara/skills, MIT.

More from dhruvanbhalara/skills

Signals

Stars
30
Forks
4
Open issues
0
Last commit (this folder)
Aug 29, 2026 (2 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from dhruvanbhalara

Cite this page

flutter-add-widget-preview skill. Agent Mart. https://agentmart.dev/skills/dhruvanbhalara-flutter-add-widget-preview (last updated 2026-10-24)