gpt_markdown documentation
The complete guide to gpt_markdown. Start with one widget, then learn every supported rendering behavior, customization layer, inline extension point, test strategy, and migration consideration.
Quick start
1flutter pub add gpt_markdown1import 'package:gpt_markdown/gpt_markdown.dart';
2
3GptMarkdown(
4 r'**Hello!** Inline math: \( E = mc^2 \)',
5)This renders common Markdown and LaTeX immediately. Use a latexBuilder only when your app needs to replace the default math widget.
Long documents with SliverGptMarkdown
Use SliverGptMarkdown inside CustomScrollView.slivers when a long AI response, generated report, article, or documentation page has its own scrollable viewport.
1SelectionArea(
2 child: CustomScrollView(
3 slivers: [
4 const SliverAppBar(
5 title: Text('AI response'),
6 ),
7 SliverGptMarkdown(
8 longResponse,
9 config: const GptMarkdownConfig(
10 style: TextStyle(fontSize: 16),
11 ),
12 ),
13 ],
14 ),
15)Viewport-lazy rendering
The source is segmented first, but Markdown spans and widgets are created only when the viewport approaches each segment. Offscreen work waits until it is needed.
Better long-document performance
Delaying offscreen parsing and widget construction reduces initial rendering and layout work compared with placing a full GptMarkdown document inside a SingleChildScrollView.
Keep GptMarkdown for compact content and character-by-character streaming reveal. SliverGptMarkdown displays source updates immediately and prioritizes viewport laziness for long content.
Three ways to customize
- Style sheets and themes change appearance without replacing the renderer.
- Builders and callbacks replace supported structures or connect interactions to your app.
- Patterns and components turn app-specific tokens such as
@mentionsinto native inline UI.
Complete package coverage
These pages cover the package's full documentation set in the website itself: getting started, customization, streaming, inline syntax, custom components, testing, and migration—alongside focused rendering and API references.
How to choose a customization tool
| Need | Use | Why |
|---|---|---|
| Change colour, size, padding, or font | Style object | Keeps the package structure and future component improvements. |
| Replace a component's widget structure | Builder | Use only when the default structure is genuinely not enough. |
- A WidgetSpan inside a link label does not paint on iOS; declare safe scopes for custom components.
- Changing a builder at runtime needs a remount because closures are not compared for span caching.
- Markdown text lives in spans, so
find.textis not the normal widget-test assertion.
Get started
Core guides
See the supported Markdown, citations, links, lists, tables, and more.
Use autolinks, app URL schemes, mentions, channels, emoji, and safe text spans.
Reveal a reply as it arrives, then finish cleanly.
Render equations, choose delimiters, and handle wide formulas.
Control fenced code, copy actions, and incomplete streamed fences.
Customize
Reference
Look up every parameter, callback, and supported replacement hook.
Test rendered spans, streaming, text scale, style merges, goldens, and documentation snippets.
Move from the legacy regex parser to the cached plusparse pipeline without missing behavior changes.
