Skip to main content
skill Claude Code CX Codex Cursor GitHub Copilot

dart-use-doc-examples — Claude Code skill: inject code into Dartdoc

Teaches agents to inject external code examples into Dartdoc using the {@example} directive instead of inline blocks.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add flutter/agent-plugins --skill dart-use-doc-examples -a claude-code
Open on GitHub

What dart-use-doc-examples does

The skill explains how to pull .dart example files into method and class documentation using {@example}. The agent learns the directive syntax, how to work with regions (#region/#endregion) to extract specific fragments, and the #hide marker to suppress setup lines that the compiler needs but readers do not.

Paths can start from the package root (/example/client.dart) or resolve relative to the current file. Regions let you carve out a specific block while hiding imports and void main() wrappers. Lines marked with #hide vanish completely from the generated documentation. After injecting examples, the skill recommends running dart analyze to verify the hidden code still compiles.

What it helps with

  • inject an external example file into a Dartdoc comment
  • extract a specific code region while hiding imports and setup
  • suppress a setup line from documentation readers using #hide
  • resolve example file paths from package root or relative to current file
  • verify hidden code compiles with dart analyze

Example prompts for the agent

  • Inject the code example from `/example/client.dart` using `{@example}`
  • Extract only the `request_snippet` region from the example file, hide imports
  • Hide the `mockServer` setup line with `#hide` in the doc example

How to install dart-use-doc-examples

1Skills CLI (Vercel)

npx skills add flutter/agent-plugins --skill dart-use-doc-examples -a claude-code

2Manually: put the files in place

~/.claude/skills/dart-use-doc-examples/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/dart-use-doc-examples/

From the same set14

The whole set →
flutter-apply-architecture-best-practices flutter This skill structures Flutter apps around UI, Logic, and Data layers. Use it when starting a project or refactoring code for scale. Claude Code CX Codex Cursor +1 43,000installs flutter-build-responsive-layout flutter This skill guides coding agents to build adaptive Flutter UIs across mobile and desktop screens using LayoutBuilder and BoxConstraints. Claude Code CX Codex Cursor +1 42,300installs flutter-add-widget-test flutter A skill that teaches AI coders to write component-level Flutter tests using WidgetTester. Verifies how widgets render and respond to taps, scrolling, and text input. Claude Code CX Codex Cursor +1 39,000installs flutter-add-integration-test flutter Sets up the integration_test package for Flutter and turns MCP session interactions into repeatable end-to-end tests. Claude Code CX Codex Cursor +1 38,000installs flutter-setup-declarative-routing flutter Sets up Flutter routing with go_router, including URL-based screens, nested navigation, and deep links for web and mobile apps. Claude Code CX Codex Cursor +1 37,600installs flutter-implement-json-serialization flutter Teaches coding agents to build Dart models with fromJson and toJson methods using dart:convert. Useful for manual JSON mapping in simple Flutter data structures. Claude Code CX Codex Cursor +1 37,200installs flutter-add-widget-preview flutter Configures interactive Flutter widget previews with package:flutter/widget_previews.dart. Useful for testing UI components in isolation without launching the whole app. Claude Code CX Codex Cursor +1 36,600installs flutter-setup-localization flutter This skill automates initialization of multi-language support in Flutter projects. It adds dependencies, enables code generation, and creates a configuration file for .arb-based translations. Claude Code CX Codex Cursor +1 36,600installs

Similar

book-study sanyuan0704 Guides book study by chapter, compiling notes, testing understanding, and scheduling review. Use it when you want a reading plan with questions and progress tracking. Claude Code CX Codex Cursor +1 3,500installs fact-check leonardomso Verifies technical accuracy in JavaScript educational pages by checking code snippets against MDN documentation and the ECMAScript specification. Claude Code CX Codex Cursor +1 331installs file-conversion Seth Hobson Converts local media, documents, and data formats using tools already installed on your machine. Prevents uploading files to third-party APIs. Claude Code CX Codex Cursor 3,100installs concept-workflow leonardomso Orchestrates end-to-end JavaScript concept documentation from research and drafting to testing and SEO checks. Useful when writing new guides or rebuilding existing pages. Claude Code CX Codex Cursor +1 322installs resource-curator leonardomso Audits, discovers, and organizes external learning resources for JavaScript concept documentation. It weeds out broken links and obsolete syntax. Claude Code CX Codex Cursor +1 319installs write-docs tldraw Skill for writing and updating tldraw SDK documentation. Guides you through creating articles, updating existing docs, and following the project's style. Claude Code CX Codex Cursor +1 486installs grill-with-docs Matt Pocock This skill interviews you about a plan or design and creates ADRs and a glossary along the way. Use it when decisions need sharper definition. Claude Code 1,219,756installs skill-creator official anthropics Creates and refines skills, then tests them with prompts, evaluations, and performance checks. Claude Code Claude.ai 414,180installs

Questions about dart-use-doc-examples

How to install dart-use-doc-examples in Claude Code?

Run npx skills add flutter/agent-plugins --skill dart-use-doc-examples -a claude-code in your project terminal.

What does dart-use-doc-examples do?

The skill teaches agents to inject external code examples into Dartdoc using the {@example} directive, hide setup code with #hide, and extract specific regions from example files.

How do I show only part of a code file in documentation?

Wrap the desired fragment with #region region_name and #endregion region_name comments, then call {@example /path/to/file.dart#region_name} in Dartdoc.

Source text

SKILL.md · BSD-3-Clause
---
name: dart-use-doc-examples
description: "How to inject external code examples into Dartdoc using the {@example} directive, and how to filter those files using #hide, #region, and #endregion tags."
---

# Using Examples in Dartdoc

## Contents
*   [1. The `{@example}` Directive](#1-the-example-directive)
*   [2. Using Regions](#2-using-regions)
*   [3. Hiding Setup Code](#3-hiding-setup-code)
*   [4. Marker Filtering Rules](#4-marker-filtering-rules)
*   [5. Placement and Path Resolution](#5-placement-and-path-resolution)
*   [6. Verification](#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):*
```dart
/// Makes a client service request to the backend.
///
/// ```dart
/// final client = Client();
/// client.send();
/// ```
```

*Good (External File Injection):*
```dart
/// 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`):**
```dart
import 'package:http/http.dart';

void main() {
  // #region request_snippet
  final client = Client();
  client.send();
  // #endregion request_snippet
}
```

**Dartdoc Usage:**
```dart
/// 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:**
```dart
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 `# #region` or 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`.
*   **Relative Paths**: Paths without a leading slash resolve relative to the directory of the file containing the doc comment.
    *   *Example:* `{@example ../utils/demo.dart}`
*   **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 `%20` for spaces) as permitted by URI reference rules.

## 6. Verification
After injecting examples:
1.  Run `dart analyze` on the example files to ensure the hidden setup code compiles.
2.  (Optional) Run `dart doc` to verify that dartdoc successfully parsed the directive without throwing a "Failed to read file" or "missing region" warning.

© flutter · BSD-3-Clause · flutter/agent-plugins

See also

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor