Teaching Your IDE to Show Icons: Inline SVG Previews in Dartdoc Comments

My icon packages show each icon as a picture in the IDE's hover tooltip, with no plugin, no extension, and no runtime cost.
The code generator embeds each icon's SVG in its doc comment as a base64 data: URI.
I now use this approach across five icon-related repos.
The problem it solves: you type LucideIcons. and the IDE offers you 2,023 options with names like pencilSparkles, beefOff, and squirrel.
Nothing tells you which one is the icon you saw in the design mock.
So you alt-tab to lucide.dev, search, alt-tab back, pick, hot-reload, find it was the wrong one, and repeat.
The names are accurate, but names are the wrong medium. An icon is a picture, and the tooltip should show it.
Doc comments are markdown, and markdown can embed a data URI
Dart doc comments are markdown, and modern IDEs (VS Code and Android Studio both) render that markdown in hover tooltips and autocomplete detail panes.
Markdown can embed images, images can be data: URIs, and an SVG is text.
So my lucide_icons fork's code generator base64-encodes each icon's SVG and writes it straight into the /// comment:
String _svgDataUriFromContent(String svgContent) {
final normalizedSvg = svgContent.trim();
final base64Svg = base64.encode(utf8.encode(normalizedSvg));
return 'data:image/svg+xml;base64,$base64Svg';
}
The generated output has one entry per icon (base64 truncated here):
/// [](https://lucide.dev/icons/pencil-sparkles)
/// Lucide icon named "pencil sparkles".
static const IconData pencilSparkles = IconData(
0xE70F,
fontFamily: 'Lucide',
fontPackage: 'lucide_icons',
);
The markdown shape is [](docsUrl): an image inside a link.
Hovering shows the icon, and clicking the preview opens that icon's page on lucide.dev.
Now hovering LucideIcons.pencilSparkles shows you a pencil with sparkles, in the editor, offline, instantly.
The previews add no runtime, network, or tooling cost
- Zero runtime bytes. Comments don't survive compilation. Your app binary contains exactly as much SVG as before: none.
- Zero network. The image data is in the file. Previews work offline and during a registry outage.
- Zero tooling. No IDE plugin to install or keep updated. Anything that renders dartdoc markdown gets previews for free.
The cost is paid entirely in the generated source file, which is now 16,190 lines long. That matters less than it sounds, because nobody reads a generated icon registry; they hover it.
Embedded content makes the comments churn
Embedding content in comments means the comments change when the content does. I've had to manage two problems.
The license header changes every string.
Each embedded SVG includes upstream's <!-- @license lucide-static vX.Y.Z --> header, so every version bump changes every base64 string: around 4,000 changed lines per icon-set update, even when the actual glyphs barely moved.
Stripping the header before encoding is on my list.
Until then, the diffs stay unreadable.
Formatting is part of the contract. Early on, the generator emitted everything single-line.
dart format in CI then rewrote the whole file, which made every diff all-lines-changed and quietly broke a changelog script that counted added and removed icons by grepping the diff.
The fix: the generator pipeline formats its own output (page width 80) before committing.
If a machine writes code that another machine diffs, the formatter is part of the generator.
The refresh loop is deliberately simple.
Dependabot watches the upstream lucide-static npm package daily, and a workflow_dispatch action regenerates the Dart file, bumps the version, and opens a PR.
On the 1.17.0→1.24.0 jump, that pipeline reported 33 icons added, 0 removed, and 0 of 1,958 shared codepoints shifted.
The shifted-codepoint count is the number I care about, because a shifted codepoint silently swaps icons in every consuming app.
Additions are safe; removals and shifts are the breaking changes.
A guard that auto-merges the safe case is designed but not yet wired up, so for now a human (me) still presses the button.
Five repos use the same approach
The approach has spread through my icon projects:
mingcute_iconsandvscode_codiconscarry a byte-identical copy of the samegenerate_fonts.dart. The generator grew flags (--npm-package,--css-prefix,--font-family, …) so it could stop being lucide-specific. Its CSS parser now tolerates each set's dialect quirks: MingCute writes:beforeinstead of::before, Codicons omits a semicolon, and Bootstrap has icons named things like1-circle, which Dart can't use as identifiers at all. That last case shows the generator was written with a fourth icon set in mind.bootstrap_iconspredates it and still ships its own TypeScript pipeline, so the leading-digit branch is waiting for a port that hasn't happened.flutter_icon_forge, a from-scratch icon-font toolkit, reimplements the idea independently (plainwithout the link wrapper) and adds anicons.lockfile for append-only codepoint stability.icon_font_generator, my fork of an older generator, does the HTML-flavored variant:<image width='32px' src='data:image/svg+xml;base64,…'>, which also lets you pin the render size.
Markdown image versus HTML tag is a real choice.
The markdown form is more portable across renderers, and the HTML form gives you a width.
I've shipped both.
pub.dev's hosted docs strip the previews
This post claims IDE previews, and that claim holds through pub.dev distribution.
My published icon packages carry the same generated comments (flutter_mingcute is live on pub.dev), and hovers work on a plain flutter pub add install, with no git dependency required.
The hosted docs are different: pub.dev's HTML sanitizer strips data: image sources.
On the flutter_mingcute API docs, each icon's <img> tag survives, still wrapped in its docs link, but its src is gone, so it renders as nothing (checked July 2026).
This is not specific to my generator: other icon packages on pub.dev that embed data-URI previews lose them on their doc pages the same way.
So the preview lives where you make decisions, in the editor, and not on the doc website.
That is an acceptable trade-off, but since dartdoc could plausibly allowlist data:image/svg+xml, I'm planning to raise this upstream.
Applying this to your own generated code
- Treat the doc comment as a UI surface. We treat dartdoc as prose for future readers, but the IDE renders it at the point of decision. For visual assets, put the visual there.
- Use data URIs as the dependency-free delivery mechanism. No CDN, no assets pipeline, no plugin: just text that happens to be an image.
- Let a generator own the file. Nobody hand-maintains 2,023 doc comments with base64 blobs. The approach is only viable because a generator owns the file, and once it does, size objections mostly go away.
- If machines diff your output, make formatting part of the generator. Skipping that cost me a broken changelog script.
If your IDE has been making you memorize icon names, try encoding a few SVGs into the docs and hovering. If you've tested this in other renderers, such as JetBrains hovers, GitHub's markdown view, or a documentation pipeline I haven't used, please tell me in the comments what rendered and what didn't.
Get the next post.
Follow new posts in your RSS reader.