streamdown 0.1.0
streamdown: ^0.1.0 copied to clipboard
Flicker-free streaming markdown renderer for Flutter AI apps. Drop-in replacement for flutter_markdown with no flash on partial code fences, tables, or LaTeX.
streamdown #
Flicker-free streaming markdown for Flutter AI apps. 188× faster than flutter_markdown on chunked input. Drop-in API.

30-second adoption #
// Before
Markdown(data: response)
// After
Streamdown(stream: openai.responseStream)
dependencies:
streamdown: ^0.1.0
That's it. Theme, code highlighting, link tap, and selectable text Just Work out of the box.
Why streamdown? #
flutter_markdown re-parses the entire string on every chunk. For a 2000-token GPT response, that's ~400 re-parses + full re-highlight of code blocks + LaTeX re-renders. Result: visible flicker, jumping cursor, code blocks that flash unstyled → styled.
streamdown keeps an append-only AST, renders incomplete blocks provisionally (e.g., a half-finished ```dart becomes a code block immediately), and uses stable widget keys so Flutter's diff doesn't tear down + rebuild on every token.
flutter_markdown |
streamdown |
|
|---|---|---|
| Re-parse on every chunk | ✅ (slow) | ❌ (incremental) |
| Provisional code fence rendering | ❌ | ✅ |
| Provisional table rows | ❌ | ✅ |
| Stable widget keys during stream | ❌ | ✅ |
| Per-line syntax highlighting cache | ❌ | ✅ |
| LaTeX (optional) | ✅ | ✅ |
| Bundle size | ~80KB | <50KB |
Headline benchmark — 5KB markdown, 4-char chunks (typical AI stream cadence): streamdown is ~188× faster than re-parsing from scratch on every chunk. See test/perf/benchmark_test.dart.
Advanced usage #
Streamdown(
stream: openai.responseStream,
syntaxTheme: SyntaxTheme.githubDark,
latex: true,
selectable: true,
onLinkTap: (uri) => launchUrl(uri),
codeBlockBuilder: (lang, code, isComplete) => MyCustomCodeBlock(...),
)
See example/ for six runnable scenarios including a side-by-side comparison with flutter_markdown.
How it works #
Three tricks combined:
- Incremental token-level parser — new tokens extend the trailing AST node; the prefix is never re-tokenized.
- Provisional rendering — an unclosed code fence renders as a code block immediately, then continues filling as lines stream in.
- Diff-stable widget keys — every AST node gets a deterministic key so Flutter's element diff doesn't tear down existing widgets.
See the architecture notes in CLAUDE.md.
Run the demos #
git clone https://github.com/jayu1023/streamdown
cd streamdown/example
flutter run
Six scenarios are included:
- Comparison demo — same stream rendered by
flutter_markdown(janky) vsstreamdown(smooth). - AI chat simulator — mocked LLM stream you can wire to your own provider.
- Syntax theme gallery —
githubLight,atomOneDark, andautoside-by-side. - Custom code block builder — replace the default with your own widget.
- Long-form article — static render of a multi-section markdown doc.
- LaTeX math — inline and block math via
flutter_math_fork.
Used by #
Building something with streamdown? Open a PR adding your project here, or drop a note in Discussions.
Contributing #
Issues and PRs welcome. See GitHub Issues.
License #
BSD-3-Clause. See LICENSE.
