跳到主内容
智客 ZICQ

技能库 智客分类:设计创意 flutter-add-widget-preview

Flutter Add Widget Preview

使用预览.dart系统为工程添加交互式部件预览. 在创建新的UI组件或更新已存在的屏幕时使用,以确保一致的设计和交互测试.

38550 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

使用预览向工程添加交互式部件预览 。 飞镖系统

何时用

创建新的 UI 组件或更新现有的屏幕,以确保一致的设计和交互测试

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:Previewing Flutter Widgets、Contents、Preview Guidelines、Handling Limitations、Workflows、Creating a Widget Preview。 其中含规范建议的小节:分步指令、输入输出示例、边界情况。

文件分析

文件分析:除 SKILL.md 外,正文引用了 assets/my_image.png,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Adds interactive widget previews to the project using the previews.dart system. Use when creating new UI components or updating existing screens to ensure consistent design and interactive testing.

Previewing Flutter WidgetsContentsPreview GuidelinesHandling LimitationsWorkflowsCreating a Widget PreviewInteracting with PreviewsExamplesBasic PreviewCustom Preview with Runtime TransformationMultiPreview Implementation

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
flutter-add-widget-preview
description
Adds interactive widget previews to the project using the previews.dart system. Use when creating new UI components or updating existing screens to ensure consistent design and interactive testing.
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 1
  • assets/my_image.png

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「flutter-add-widget-preview」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-ec8adb6880805ae2-%E5%B0%8F%E8%9D%B6%E6%B7%BB%E5%8A%A0%E9%83%A8%E4%BB%B6%E9%A2%84%E8%A7%88.html
请存为 .cursor/skills/flutter-add-widget-preview/SKILL.md 或 .claude/skills/flutter-add-widget-preview/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/flutter/agent-plugins 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/flutter/agent-plugins' --list

npx skills add 'https://github.com/flutter/agent-plugins' --skill 'flutter-add-widget-preview'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版
--- name: flutter-add-widget-preview description: Adds interactive widget previews to the project using the previews.dart system. Use when creating new UI components or updating existing screens to ensure consistent design and interactive testing. metadata: model: models/gemini-3.1-pro-preview last_modified: Tue, 21 Apr 2026 20:05:23 GMT --- # Previewing Flutter Widgets ## Contents - [Preview Guidelines](#preview-guidelines) - [Handling Limitations](#handling-limitations) - [Workflows](#workflows) - [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, static methods within a class, or public widget constructors/factories that have no required arguments and return a `Widget` or `WidgetBuilder`. - **Imports:** Always import `package:flutter/widget_previews.dart` to access the preview annotations. - **Custom Annotations:** Extend the `Preview` class to create custom annotations that inject common properties (e.g., themes, wrappers) across multiple widgets. - **Multiple Configurations:** Apply multiple `@Preview` annotations to a single target to generate multiple preview instances. Alternatively, extend `MultiPreview` to encapsulate common multi-preview configurations. - **Runtime Transformations:** Override the `transform()` method in custom `Preview` or `MultiPreview` classes to modify preview configurations dynamically at runtime (e.g., generating names based on dynamic values, which is impossible in a `const` context). ## Handling Limitations Adhere to the following constraints when authoring previewable widgets, as the Widget Previewer runs in a web environment: - **No Native APIs:** Do not use native plugins or APIs from `dart:io` or `dart:ffi`. Widgets with transitive dependencies on `dart:io` or `dart:ffi` will throw exceptions upon invocation. Use conditional imports to mock or bypass these in preview mode. - **Asset Paths:** Use package-based paths for assets loaded via `dart:ui` `fromAsset` APIs (e.g., `packages/my_package_name/assets/my_image.png` instead of `assets/my_image.png`). - **Public Callbacks:** Ensure all callback arguments provided to preview annotations are public and constant to satisfy code generation requirements. - **Constraints:** Apply explicit constraints using the `size` parameter in the `@Preview` annotation if your widget is unconstrained, as the previewer defaults to constraining them to approximately half the viewport. ## Workflows ### Creating a Widget Preview Copy and track this checklist when implementing a new widget preview: - [ ] Import `package:flutter/widget_previews.dart`. - [ ] Identify a valid target (top-level function, static method, or parameter-less public constructor). - [ ] Apply the `@Preview` annotation to the target. - [ ] Configure preview parameters (`name`, `group`, `size`, `theme`, `brightness`, etc.) as needed. - [ ] If applying the same configuration to multiple widgets, extract the configuration into a custom class extending `Preview`. ### Interacting with Previews Follow the appropriate conditional workflow to launch and interact with the Widget Previewer: **If using a supported 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 if you want to view previews outside the currently active file. **If using the Command Line:** 1. Navigate to the Flutter project's root directory. 2. Run `flutter widget-preview start`. 3. View the automatically opened Chrome environment. **Feedback Loop: Preview Iteration** 1. Modify the widget code or preview configuration. 2. Observe the automatic update in the Widget Previewer. 3. If global state (e.g., static initializers) was modified: Click the global hot restart button at the bottom right. 4. If only the local widget state needs resetting: Click the individual hot restart button on the specific preview card. 5. Review errors in the IDE/CLI console -> fix -> repeat. ## Examples ### Basic Preview ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; @Preview(name: 'My Sample Text', group: 'Typography') Widget mySampleText() { return const Text('Hello, World!'); } ``` ### Custom Preview with Runtime Transformation ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; final class TransformativePreview extends Preview { const TransformativePreview({ 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(); builder ..name = 'Transformed - ${originalPreview.name}' ..theme = _themeBuilder; return builder.toPreview(); } } @TransformativePreview(name: 'Custom Themed Button') Widget myButton() => const ElevatedButton(onPressed: null, child: Text('Click')); ``` ### MultiPreview Implementation ```dart import 'package:flutter/widget_previews.dart'; import 'package:flutter/material.dart'; /// Creates light and dark mode previews automatically. final class MultiBrightnessPreview extends MultiPreview { const MultiBrightnessPreview({required this.name}); final String name; @override List get previews => const [ Preview(brightness: Brightness.light), Preview(brightness: Brightness.dark), ]; @override List transform() { final previews = super.transform(); return previews.map((preview) { final builder = preview.toBuilder() ..group = 'Brightness' ..name = '$name - ${preview.brightness!.name}'; return builder.toPreview(); }).toList(); } } @MultiBrightnessPreview(name: 'Primary Card') Widget cardPreview() => const Card(child: Padding(padding: EdgeInsets.all(8.0), child: Text('Content'))); ```

相关技能

设计创意

Automation Workflows

设计和实施自动化工作流程,以节省时间和规模化操作作为独家. 用于识别重复任务实现自动化,构建跨工具的工作流程,设置触发器和行动,或优化现有自动化. 包括自动化机会识别,工作流程设计,工具选择(Zapier,Make,n8n),测试,和维护. 触发"自动","自动","工作流程自动…

设计创意

Ui Ux Pro Max

UI/UX设计智能及建筑抛光接口实施指导. 当用户要求UI设计,UX流量,信息架构,视觉风格方向,设计系统/托盘,组件规格,副本/显微镜,可访问性,或生成/critique/refine前端UI(HTML/CSS/JS,React,Next.js,Vue,Svelte,Tailw…

设计创意

Frontend Design

创建美丽现代UI的专家前端设计指南. 在构建起落架页面,仪表板,或任何用户界面时使用.

设计创意

N8n Workflow Automation

设计和输出 n8n 工作流程 JSON 有强力触发器, idempotency, 错误处理, 记录, 重试, 以及 人入"一站"审查队列. 当您需要可审计的自动化时使用.