utsavsavani08/rain-skill-main/flutter-add-widget-preview

Claude Code and agent skill by utsavsavani08/rain-skill-main

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Flutter widget preview expert. Load for adding interactive widget previews using the @Preview annotation and previews.dart system — IDE-integrated visual testing without running the full app. Triggers on: widget preview, @Preview, flutter widget-preview, previews.dart, preview annotation, MultiPreview, WidgetPreview.

Install

npx vskill@latest install utsavsavani08/rain-skill-main/flutter-add-widget-preview

SKILL.md

The same SKILL.md was published earlier as utsavsavani08/rain-skill-main/flutter-add-widget-preview.

Flutter Widget Preview — Interactive UI Previews

Add @Preview annotations to render widgets in the IDE without launching a device or emulator.

What widget previews are

Widget previews let you view and interact with individual Flutter widgets directly in your IDE (Android Studio, IntelliJ, VS Code 3.38+) using the flutter widget-preview start command. No full app launch required.


Mandatory checkpoint (before adding previews)

👁️ PREVIEW CHECKPOINT:
IDE version: [ Android Studio / IntelliJ / VS Code 3.38+ ]
Flutter channel: [ main or master — previews are experimental ]
Target widget: [ stateless / stateful / complex ]
Assets needed: [ package-relative paths required ]

@Preview annotation rules

Allowed targetsNot allowed
Top-level functionsInstance methods
Static class methodsdart:io / dart:ffi APIs
Public widget constructorsPlatform channels
Public factory constructorsNative-dependent code

The annotated function must:

  • Take no required arguments (or have all defaults provided)
  • Return Widget or WidgetBuilder

Basic preview

dart
import 'package:flutter/widgets.dart';
// Simple widget
class GreetingCard extends StatelessWidget {
final String name;
const GreetingCard({super.key, required this.name});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
color: Colors.blue.shade50,
child: Text('Hello, $name!', style: const TextStyle(fontSize: 24)),
);
}
}
// Preview function — top-level, no required args
@Preview()
Widget greetingCardPreview() => const GreetingCard(name: 'Alice');

Sized preview (explicit constraints)

Use when the widget needs bounded dimensions to render correctly.

dart
@Preview()
Widget buttonPreview() => const SizedBox(
width: 200,
height: 56,
child: ElevatedButton(
onPressed: null,
child: Text('Submit'),
),
);

Custom preview class (with transformations)

Extend Preview to apply consistent wrappers — themes, padding, locale.

dart
class DarkThemePreview extends Preview {
const DarkThemePreview() : super();
@override
Widget wrap(Widget child) => MaterialApp(
theme: ThemeData.dark(),
home: Scaffold(body: Center(child: child)),
);
}
@DarkThemePreview()
Widget cardDarkPreview() => const GreetingCard(name: 'Bob');

MultiPreview — generate multiple variants

Use @MultiPreview to automatically produce several previews from a single annotation.

dart
// Define the multi-preview annotation
class LightAndDark extends MultiPreview {
const LightAndDark() : super([
Preview(name: 'Light', theme: PreviewTheme.light),
Preview(name: 'Dark', theme: PreviewTheme.dark),
]);
}
// Apply to widget
@LightAndDark()
Widget themedButtonPreview() => const PrimaryButton(label: 'Continue');

Asset paths in previews

Never use relative or File-based paths. Use package-relative asset paths.

dart
// ❌ WRONG — breaks in preview context
Image.asset('assets/images/logo.png')
// ✅ CORRECT — package-relative path
Image.asset('packages/my_app/assets/images/logo.png')

Running previews

Via IDE
  • VS Code: Open a file with @Preview annotations → click "Open Preview" in the editor toolbar
  • Android Studio / IntelliJ: Gutter icon appears next to preview functions → click to render
Via CLI
bash
# Start preview server (run once per session)
flutter widget-preview start
# Preview hot-restarts automatically on file save
# Stop with Ctrl+C

Preview iteration loop

1. Write widget code
2. Add @Preview() function
3. flutter widget-preview start (or use IDE panel)
4. Edit widget → save → preview hot-reloads
5. Test interactions directly in preview panel
6. When satisfied, remove preview functions before committing (optional)

Organizing previews

lib/
├── features/
│ └── profile/
│ ├── profile_card.dart # widget
│ └── profile_card_preview.dart # previews — keep separate
├── shared/
│ └── widgets/
│ ├── primary_button.dart
│ └── primary_button_preview.dart

Keeping previews in separate _preview.dart files avoids polluting production code with preview annotations.


Common errors and fixes

ErrorCauseFix
Preview not showing in IDEFlutter channel not main/masterSwitch with flutter channel main
dart:io error in previewUsing File, Platform, etc.Remove native API usage from preview path
Asset not loadingRelative asset pathUse packages/<name>/assets/... format
Preview crashes silentlyException in widget constructorWrap preview body in Builder with error boundary
Callback not workingNon-constant callback passedUse null or a top-level constant callback

Hard rules

  1. No `dart:io` or `dart:ffi` in any code path reachable from a preview.
  2. No required arguments on preview functions — defaults or constants only.
  3. Always use package-relative asset paths inside previews.
  4. Keep preview functions in separate files — don't mix with production logic.
  5. Never ship preview annotations to production without a clear keep/remove decision.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/utsavsavani08/rain-skill-main/flutter-add-widget-preview/badge)](https://verified-skill.com/skills/utsavsavani08/rain-skill-main/flutter-add-widget-preview)

Something wrong with this skill or its page? Tell us.