Menu

1 / 2

Streaming ChatGPT and Gemini replies in Flutter without the flicker

DEV Community: dart·Anant mandanka·4 days ago
#havXCgUJ
#devtodart#devto#dev#reply#controller
Long article (811 words) — no AI summary yet.
Reading 0:00
15s threshold

If you have built an AI chat screen in Flutter, you have probably seen this: the reply streams in, and the screen fights it. Raw ** shows up until the closing pair arrives, a code block jumps when the highlighter kicks in, and long answers get slower with every chunk.

I hit all of that while building chat screens, so I wrote llm_markdown , a Markdown widget made for replies that are still being written. This post shows why the usual approach struggles and how to stream a reply smoothly.

Try the live demo in your browser

Why the usual way flickers

The common setup is a regular Markdown widget rebuilt with the whole text on every chunk:

MarkdownBody ( data : textSoFar ) // rebuilt for every chunk

Enter fullscreen mode

Exit fullscreen mode

That has three problems while a reply streams:

Everything is parsed again on every chunk. A 20,000 character answer arrives in a few thousand chunks, so the work per chunk keeps growing with the reply.

Half-typed syntax shows raw.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.