Skills
Skill 10 of 31
How to inject external code examples into Dartdoc using the {@example} directive, and how to filter those files using #hide, #region, and #endregion tags.
2 minutes · 543 words · 8 sections
Install
npx skills add flutter/agent-plugins --skill dart-use-doc-examplesnpx skills add flutter/agent-plugins/plugin marketplace add flutter/agent-pluginsThe first command installs just this skill, by the name in its SKILL.md; the second installs the whole repository.
{@example} DirectiveWhen 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.
{@example} DirectiveThe {@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}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}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.
When working with #hide, #region, and #endregion markers, you must follow these two technical constraints:
{@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.# #region or HTML comments <!-- #region -->).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:
/): 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 /test/data/sample.txt} exactly maps to <package_root>/test/data/sample.txt.{@example ../utils/demo.dart}.. segments to traverse upward is perfectly acceptable, but dartdoc natively stops directory traversal at the package root (it will never escape the package).https://) are strictly not supported. The example file must sit natively somewhere in the local filesystem./) as folder separators (even on Windows). You can natively include URI-encoded characters (like %20 for spaces) as permitted by URI reference rules.After injecting examples:
dart analyze on the example files to ensure the hidden setup code compiles.dart doc to verify that dartdoc successfully parsed the directive without throwing a “Failed to read file” or “missing region” warning.main, last pushed 17 September 2026.SKILL.md, not by matching a directory convention. 2 distinct layouts observed: .agents/agents/reidbaker-agent/skills/*/SKILL.md, skills/*/SKILL.md.h1 and no skipped levels:.claude-plugin/marketplace.json by Dart and Flutter Team, declaring 1 plugin. It is read for editorial metadata only — never as the skill index, which is always the repository tree./flutter/agent-plugins.md, and each skill at its own .md URL.