Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/flutter/agent-plugins --skill dart-use-doc-examples- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads dart-use-doc-examples automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
Security audits
Independent scans of the skill's instructions and bundled files.
SKILL.md
The instructions your agent reads when the skill is triggered.
Using Examples in Dartdoc
Contents
- 1. The
{@example}Directive - 2. Using Regions
- 3. Hiding Setup Code
- 4. Marker Filtering Rules
- 5. Placement and Path Resolution
- 6. Verification
When writing documentation that requires multi-line code examples, you should generally extract those examples into standalone .dart files and inject them using the {@example} directive, rather than writing them inline inside /// comments. This ensures the examples can be analyzed, linted, and executed.
1. The {@example} Directive
The {@example} directive parses an external file and resolves it into a fenced Markdown code block in the generated documentation.
Syntax: {@example <path>[#<region>] [lang=LANGUAGE] [indent=keep|strip]}
<path>: The path to the file. A leading/evaluates from the package root. Otherwise, it is relative to the current file.lang: The language for the markdown fence. Auto-detected from the file extension (e.g.,dart), but can be explicit (e.g.,lang=text).indent:strip(default) aggressively removes shared leading indentation from the code block.
Bad (Inline Markdown):
/// Makes a client service request to the backend.
///
/// ```dart
/// final client = Client();
/// client.send();
/// ```
Good (External File Injection):
/// Makes a client service request to the backend.
///
/// {@example /example/client_request.dart}
2. Using Regions
Often, an external example file contains imports, setup, or void main() wrappers that you don't want to show in the documentation. You can extract a specific block of code by appending #<region> to the {@example} directive path, and wrapping that code with #region and #endregion comments in the target file.
Dart Code (e.g., /example/client.dart):
import 'package:http/http.dart';
void main() {
// #region request_snippet
final client = Client();
client.send();
// #endregion request_snippet
}
Dartdoc Usage:
/// Connects the client to the server and sends a request.
///
/// {@example /example/client.dart#request_snippet}
3. Hiding Setup Code
If there is a specific line of code within your extracted region that is necessary for the compiler/analyzer to pass but irrelevant (or distracting) for the documentation reader, append #hide to that line.
Dart Code:
final mockServer = startServer(); // #hide
final data = await fetch(mockServer.url);
In the generated documentation, only final data = await fetch(mockServer.url); will be visible. The line with #hide is completely dropped.
4. Marker Filtering Rules
When working with #hide, #region, and #endregion markers, you must follow these two technical constraints:
- Region Required: The markers are only processed and stripped when you target a specific region suffix (e.g.,
{@example file.dart#region_name}). If you inject an entire file without a region suffix, the file is embedded exactly as it appears in the source, including any marker text like// #hide. - Format Agnosticism: The marker system is completely format-agnostic. Dartdoc simply runs a regex to strip lines containing the marker strings, meaning it works identically in non-Dart files (e.g., inside YAML comments
# #regionor HTML comments<!-- #region -->).
5. Placement and Path Resolution
The {@example} directive is a block-level directive. It must appear on its own line prefixed with ///. Its internal <path> parser follows strict URI reference rules:
- Package-Root Paths (
/): Paths starting with a leading slash automatically resolve directly to the root of the Dart package. Use this when the destination file is deep.- Example:
{@example /test/data/sample.txt}exactly maps to<package_root>/test/data/sample.txt.
- Example:
- Relative Paths: Paths without a leading slash resolve relative to the directory of the file containing the doc comment.
- Example:
{@example ../utils/demo.dart}
- Example:
- Boundary Enforcement: Using
..segments to traverse upward is perfectly acceptable, but dartdoc natively stops directory traversal at the package root (it will never escape the package). - No Network URLs: Absolute URIs (e.g., starting with
https://) are strictly not supported. The example file must sit natively somewhere in the local filesystem. - Separators & Encoding: Because dartdoc resolves the path as a URI, you must always use forward slashes (
/) as folder separators (even on Windows). You can natively include URI-encoded characters (like%20for spaces) as permitted by URI reference rules.
6. Verification
After injecting examples:
- Run
dart analyzeon the example files to ensure the hidden setup code compiles. - (Optional) Run
dart docto verify that dartdoc successfully parsed the directive without throwing a "Failed to read file" or "missing region" warning.
FAQ
What does the dart-use-doc-examples skill do?
How to inject external code examples into Dartdoc using the {@example} directive, and how to filter those files using hide, region, and endregion tags.
How do I install dart-use-doc-examples?
Run npx skills add https://github.com/flutter/agent-plugins --skill dart-use-doc-examples in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/dart-use-doc-examples/ (personal) or .claude/skills/dart-use-doc-examples/ (project).
Which AI agents can use dart-use-doc-examples?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is dart-use-doc-examples safe to install?
Security partners have reviewed it: Gen Agent Trust Hub passed; Socket passed; Snyk passed. As with any skill, read the SKILL.md and bundled scripts before installing.
Who maintains dart-use-doc-examples?
It is published by flutter in flutter/agent-plugins. It has 6,541 recorded installs.
More from flutter/agent-plugins
flutter-apply-architecture-best-practices
flutter/agent-plugins
Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
flutter-build-responsive-layout
flutter/agent-plugins
Use LayoutBuilder, MediaQuery, or Expanded/Flexible to create a layout that adapts to different screen sizes. Use when you need the UI to look good on both mobile and tablet/desktop form factors.
flutter-fix-layout-issues
flutter/agent-plugins
Fixes Flutter layout errors (overflows, unbounded constraints) using Dart and Flutter MCP tools. Use when addressing "RenderFlex overflowed", "Vertical viewport was given unbounded height", or similar layout issues.
flutter-add-widget-test
flutter/agent-plugins
Implement a component-level test using WidgetTester to verify UI rendering and user interactions (tapping, scrolling, entering text). Use when validating that a specific widget displays correct data and responds to events as expected.
flutter-add-integration-test
flutter/agent-plugins
Configures Flutter Driver for app interaction and converts MCP actions into permanent integration tests. Use when adding integration testing to a project, exploring UI components via MCP, or automating user flows with the integrationtest package.
flutter-setup-declarative-routing
flutter/agent-plugins
Configure MaterialApp.router using a package like gorouter for advanced URL-based navigation. Use when developing web applications or mobile apps that require specific deep linking and browser history support.
Popular mobile skills
design-mobile-apps
designed-by-ai/skills
Design mobile app screens with Sleek, edit Sleek projects, and implement their designs in React Native or HTML.
ios-design
uizze.sh
Design and review iOS UI/UX for iPhone apps in SwiftUI, UIKit, or React Native. Use for mobile app design, screen redesigns, navigation flows, typography, forms, keyboard and safe-area layout, and accessibility checks. Apply Apple Human Interface Guidelines and consult real product references through the optional Uizze connection.
vercel-react-native-skills
vercel-labs/agent-skills
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
animate-expo
emilkowalski/skills
Build animations in React Native and Expo, making the decisions in the order that determines whether they feel right — should it animate, which thread it runs on, which properties, spring or timing, how the gesture hands off, how it degrades. Writes the implementation with Reanimated, Gesture Handler, Expo Router and expo-haptics. Use when animating anything in an Expo app, adding gestures, sheets, screen transitions, press feedback or haptics, or fixing motion that stutters on device. For web animation use animate.
xcode-project-setup
firebase/agent-skills
Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).
firebase-remote-config-basics
firebase/agent-skills
Manages Firebase Remote Config templates, feature flags, loading strategies, and SDKs (Android, iOS). Use when downloading/deploying remoteconfig JSON templates, managing version history/feature flags, setting in-app defaults, fetchAndActivate(), real-time listeners, or SDK setup. Don't use for Firebase Hosting, Auth, Firestore, Data Connect, Crashlytics, or App Hosting.
