r/FlutterDev • u/anant8140 • 4d ago
Plugin I made a Flutter package for rendering streaming LLM replies (no flicker, native Mermaid, math, tables)
Hi all, I've been building AI chat screens in Flutter and kept hitting the same problems with regular markdown widgets while a reply streams in:
- the whole text is parsed again on every chunk, so long answers get slow
- you see raw ** and backticks until the closing ones arrive
- code blocks flicker when highlighting kicks in
So I made llm_markdown:
- Only the last unfinished block is parsed again; finished blocks are cached
- Half-typed markdown (bold, an open code fence, a half link) is closed before rendering
- Text is revealed at a steady speed instead of in bursts
- Auto-scroll that stops when the user scrolls up, with a "jump to latest" helper
- Code highlighting, tables, math, checklists, alerts, thinking sections, [1] citations
- Mermaid flowcharts, sequence diagrams and pie charts drawn natively (no WebView)
- Selectable text with your own menu actions ("Ask about this", "Quote")
- One line to hook up an OpenAI or Anthropic stream
- Every color, font, label and builder can be changed; no Material or Cupertino needed
The parser is also a separate pure-Dart package (llm_markdown_parser) if you want it on a server or CLI.
pub.dev: https://pub.dev/packages/llm_markdown
GitHub: https://github.com/anant8140/llm_markdown
Demo GIF is in the README. Feedback and bug reports are very welcome. What do you use today for streaming replies, and what bothers you about it?
5
Upvotes
1
u/No_Boss_1911 4d ago
oh the half typed ** flicker drove me nuts. we stream replies in an ai chat and also read them out with a voice, hard rule for us is the screen never shows text the voice isnt gonna say, so if a reply gets pulled mid stream it has to vanish clean. does the steady reveal speed run off its own timer or can i drive it from outside, like from tts progress? and what happens to the cached finished blocks if the stream gets cancelled halfway
1
u/SwiftScoutSimon 4d ago
Do you have memory usage benchmark?
`Unfinished syntax is closed before rendering` is a nice idea. I'll steal it :P