Installation
Add gpt_markdown to your Flutter project. Markdown and LaTeX rendering work immediately; use a LaTeX builder only to replace the default math widget.
Option 1 — Flutter CLI
The fastest way:
terminal
1flutter pub add gpt_markdownOption 2 — pubspec.yaml
Add it manually, then run flutter pub get:
pubspec.yaml
1dependencies:
2 gpt_markdown: ^1.3.0Import
your_file.dart
1import 'package:gpt_markdown/gpt_markdown.dart';Verify it works
Drop this anywhere in your widget tree:
main.dart
1GptMarkdown('# Hello from GPT Markdown!')Use SliverGptMarkdown for long content
The same package import also provides SliverGptMarkdown. Place it directly in the slivers list of a CustomScrollView:
sliver_markdown.dart
1SelectionArea(
2 child: CustomScrollView(
3 slivers: [
4 SliverGptMarkdown(
5 longMarkdown,
6 config: const GptMarkdownConfig(
7 style: TextStyle(fontSize: 16),
8 ),
9 ),
10 ],
11 ),
12)When it is beneficial
- Long AI answers and reports: offscreen segments delay span and widget construction until the viewport needs them.
- Mixed sliver layouts: combine Markdown with
SliverAppBar, lists, grids, headers, and other slivers in one scroll view. - Faster first viewport: less offscreen rendering and layout work is performed during the initial display.
Segmentation is eager, while built-in AST, span, and widget construction is viewport-lazy. A single very large paragraph, table, list, or code fence remains one segment. Use ordinary GptMarkdown when character reveal animation is needed.
Requirements
- A Flutter SDK that includes Dart 3.7.0 or newer
- Dart SDK 3.7.0 or higher, below 4.0.0
- No platform plugins are required. For WebAssembly, ensure the rest of your app's dependencies are also WASM-compatible.
