Menu

Streaming markdown in Flutter without the jitter
πŸ“°

Streaming markdown in Flutter without the jitter

DEV Community: dartΒ·Stephen ColorΒ·6 days ago
#mvytNoQl
#devtodart#devto#dev#block#code
Long article (962 words) β€” no AI summary yet.
Reading 0:00
15s threshold

If you have wired a model stream straight into a Flutter Text widget, you have met the three failure modes. The text jumps on bursty deltas : the network hands you three words, pauses, then twenty. Raw asterisks flash before closing markers : **imp renders as literal text until ortant** lands half a second later. The layout shifts as a code fence opens : everything below reflows when

```

arrives, and reflows again when it closes.

I fixed all three by splitting the problem into three layers β€” a typewriter buffer, a tolerant parser and a renderer that owns the caret. Here is each one, with the parts that actually mattered.

Layer 1: a typewriter buffer that can catch up

Rendering every delta is the first mistake. Delivery is bursty; reading is steady. TypewriterController sits between the stream and the UI, keeps the target string, and moves a visible cursor towards it on the vsync ticker:

final typer = TypewriterController ( vsync : this , charsPerSecond : 320 , maxBacklogSeconds : 0.9 , ) ; typer .…

Continue reading β€” create a free account

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