StreamMarkdown constructor

const StreamMarkdown({
  1. required Stream<String> stream,
  2. Key? key,
  3. MarkdownStyleSheet? styleSheet,
  4. MarkdownConfig? config,
  5. void onTapLink(
    1. String url
    )?,
  6. Widget imageBuilder(
    1. String url,
    2. String? alt,
    3. String? title
    )?,
  7. Widget codeBuilder(
    1. String code,
    2. String? language
    )?,
  8. bool useEnhancedComponents = false,
  9. Widget? loadingWidget,
  10. Widget errorBuilder(
    1. Object error
    )?,
  11. ParserPluginRegistry? plugins,
  12. 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: When true, 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,
});