StreamMarkdown constructor
const
StreamMarkdown({
- required Stream<
String> stream, - Key? key,
- MarkdownStyleSheet? styleSheet,
- MarkdownConfig? config,
- void onTapLink(
- String url
- Widget imageBuilder()?,
- Widget codeBuilder()?,
- bool useEnhancedComponents = false,
- Widget? loadingWidget,
- Widget errorBuilder(
- Object error
- ParserPluginRegistry? plugins,
- BuilderRegistry? builderRegistry,
Creates a widget that renders streaming Markdown content.
The stream parameter is required and should emit markdown text chunks.
Each chunk is appended to the accumulated content and the entire content
is re-rendered.
All other parameters are optional and provide the same customization options as SmoothMarkdown:
styleSheet: Controls the visual styling of markdown elements. Defaults to MarkdownStyleSheet.light if not provided.config: Configuration options for markdown parsing behavior.onTapLink: Callback function invoked when a link is tapped.imageBuilder: Custom widget builder for rendering images.codeBuilder: Custom widget builder for rendering code blocks.useEnhancedComponents: Whentrue, uses enhanced UI components.loadingWidget: Widget to display while waiting for the first chunk. Defaults to an empty container if not provided.errorBuilder: Custom widget builder for displaying errors. Currently not fully implemented - errors are silently ignored.
Example:
// AI chat response streaming
StreamMarkdown(
stream: aiService.streamResponse(prompt),
styleSheet: MarkdownStyleSheet.github(),
useEnhancedComponents: true,
loadingWidget: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(),
SizedBox(height: 8),
Text('Waiting for response...'),
],
),
),
onTapLink: (url) => launchUrl(Uri.parse(url)),
)
Implementation
const StreamMarkdown({
required this.stream,
super.key,
this.styleSheet,
this.config,
this.onTapLink,
this.imageBuilder,
this.codeBuilder,
this.useEnhancedComponents = false,
this.loadingWidget,
this.errorBuilder,
this.plugins,
this.builderRegistry,
});