StreamingText class
A widget that displays streaming text with real-time updates and markdown support.
This widget provides a rich text display with features like:
- Character-by-character or word-by-word typing animation
- Markdown rendering with support for bold, italic, and headers
- Fade-in animations for smooth text appearance
- RTL (Right-to-Left) language support
- Real-time text streaming capabilities
- Customizable typing speed and animation durations
Example usage:
StreamingText(
text: '**Hello** _world_!',
typingSpeed: Duration(milliseconds: 50),
fadeInEnabled: true,
wordByWord: true,
markdownEnabled: true,
)
Internally, the reveal is driven by a pure-Dart RevealEngine +
RevealScheduler pair (see lib/src/engine/): the engine is the single
source of truth for "how much of the source has been revealed", so the
rendered text is always a literal prefix of the source, and completion
(onComplete / StreamingTextController.onCompleted) fires from exactly
one place, exactly once per revealing-to-complete transition.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- StreamingText
Constructors
-
StreamingText({Key? key, required String text, Duration typingSpeed = const Duration(milliseconds: 50), TextStyle? style, StrutStyle? strutStyle, TextAlign? textAlign, TextDirection? textDirection, Locale? locale, bool? softWrap, TextOverflow? overflow, TextScaler? textScaler, int? maxLines, String? semanticsLabel, TextWidthBasis? textWidthBasis, TextHeightBehavior? textHeightBehavior, bool selectable = false, bool showCursor = true, Color? cursorColor, VoidCallback? onComplete, Stream<
String> ? stream, bool markdownEnabled = true, bool latexEnabled = false, TextStyle? latexStyle, double latexScale = 1.0, bool? latexFadeInEnabled, bool fadeInEnabled = false, Duration fadeInDuration = const Duration(milliseconds: 300), Curve fadeInCurve = Curves.easeOut, bool wordByWord = false, int chunkSize = 1, TextStyle? markdownStyleSheet, StreamingTextController? controller, bool animationsEnabled = true, bool trailingFadeEnabled = false, Widget imageBuilder(BuildContext context, String imageUrl)?, void onLinkTap(String url, String title)?, Widget codeBuilder(BuildContext context, String name, String code, bool closed)?, Widget latexBuilder(BuildContext context, String tex, TextStyle textStyle, bool inline)?, Widget sourceTagBuilder(BuildContext context, String content, TextStyle textStyle)?, Widget highlightBuilder(BuildContext context, String content, TextStyle textStyle)?, Widget linkBuilder(BuildContext context, InlineSpan text, String url, TextStyle style)?, List<MarkdownComponent> ? components, List<MarkdownComponent> ? inlineComponents, MarkdownRenderOptions? markdownOptions, bool completeAnimationOnTap = true, VoidCallback? onTextChanged, Widget errorBuilder(BuildContext context, Object error)?, RevealMode? revealMode = RevealMode.smoothFade, StreamPacing? pacing}) -
Creates a streaming text widget.
const
Properties
- animationsEnabled → bool
-
Whether animations are enabled. When false, text appears instantly.
final
- chunkSize → int
-
The number of characters revealed per animation tick when wordByWord
is
false. Ignored in word-by-word mode.final - codeBuilder → Widget Function(BuildContext context, String name, String code, bool closed)?
-
Custom builder for code blocks in markdown content.
final
- completeAnimationOnTap → bool
-
Whether tapping the widget jumps the animation to completion.
final
-
components
→ List<
MarkdownComponent> ? -
Custom block-level markdown components. Forwarded as-is to
gpt_markdown'sGptMarkdown.components. Use this to override how headers, lists, bold, italic, tables, etc. are rendered. Whennull,gpt_markdown's default component list is used.final - controller → StreamingTextController?
-
Optional controller for programmatic pause/resume/restart/skip control
and progress tracking.
final
- cursorColor → Color?
-
Color of the blinking cursor shown while showCursor is
true.final - errorBuilder → Widget Function(BuildContext context, Object error)?
-
Builder invoked when stream emits an error. Receives the error
object; the text revealed so far stays on screen either way.
final
- fadeInCurve → Curve
-
The animation curve used for the fade-in effect.
final
- fadeInDuration → Duration
-
How long each character's/word's fade-in animation takes.
final
- fadeInEnabled → bool
-
Whether each character (or word, in word-by-word mode) fades in as it is
revealed, in plain-text mode only (markdown mode never per-glyph
fades). A single Ticker drives every fading run; suppressed while the
displayed text contains Arabic.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- highlightBuilder → Widget Function(BuildContext context, String content, TextStyle textStyle)?
-
Custom builder for highlighted text in markdown content.
final
- imageBuilder → Widget Function(BuildContext context, String imageUrl)?
-
Custom builder for images in markdown content.
final
-
inlineComponents
→ List<
MarkdownComponent> ? -
Custom inline markdown components. Forwarded as-is to
gpt_markdown'sGptMarkdown.inlineComponents. Whennull,gpt_markdown's default inline component list is used.final - key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- latexBuilder → Widget Function(BuildContext context, String tex, TextStyle textStyle, bool inline)?
-
Custom builder for LaTeX expressions in markdown content.
final
- latexEnabled → bool
-
Whether to parse and render LaTeX expressions (
$...$and$$...$$).final - latexFadeInEnabled → bool?
-
Whether LaTeX content fades in as it's revealed. Defaults to matching
fadeInEnabled when
null; disabled by default for performance.final - latexScale → double
-
Scale factor applied to rendered LaTeX expressions.
final
- latexStyle → TextStyle?
-
Text style applied to rendered LaTeX expressions.
final
- linkBuilder → Widget Function(BuildContext context, InlineSpan text, String url, TextStyle style)?
-
Custom builder for links in markdown content.
final
- locale → Locale?
-
Locale used for text rendering and layout.
final
- markdownEnabled → bool
-
Whether to render text as markdown (headers, bold, lists, etc.) via
gpt_markdowninstead of as plain text.final - markdownOptions → MarkdownRenderOptions?
-
Bundles
gpt_markdown1.3 pass-throughs that don't have a dedicated top-level parameter of their own (style sheet, block/inline builders, autolink config, ...). See MarkdownRenderOptions.final - markdownStyleSheet → TextStyle?
-
Text style passed through to the markdown renderer.
final
- maxLines → int?
-
Maximum number of lines to display before truncating/overflowing.
final
- onComplete → VoidCallback?
-
Called once the animation (or stream) finishes.
final
- onLinkTap → void Function(String url, String title)?
-
Callback when a link is tapped in markdown content.
final
- onTextChanged → VoidCallback?
-
Internal hook fired whenever the revealed text grows during
animation/streaming. Not part of the public StreamingTextMarkdown API
surface directly — used internally to drive auto-scroll pinning while
content grows, rather than only once at completion.
final
- overflow → TextOverflow?
-
How visual overflow should be handled.
final
- pacing → StreamPacing?
-
How a
Stream<String>(or static text) source is paced (DESIGN.md 4.3). Whennull, stream input defaults to StreamPacing.catchUp and static text input defaults to StreamPacing.fixed using typingSpeed.final - revealMode → RevealMode?
-
How revealed text arrives on screen (DESIGN.md section 4). Defaults to
RevealMode.smoothFade.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectable → bool
-
Whether the rendered text can be selected by the user.
final
- semanticsLabel → String?
-
Semantic label used for accessibility.
final
- showCursor → bool
-
Whether to show a blinking cursor at the end of the text while
animating.
final
- softWrap → bool?
-
Whether the text should break at soft line breaks.
final
- sourceTagBuilder → Widget Function(BuildContext context, String content, TextStyle textStyle)?
-
Custom builder for source tags in markdown content.
final
-
stream
→ Stream<
String> ? -
Optional stream of text chunks. When provided, text is ignored as the
initial source and content arrives via the stream instead.
final
- strutStyle → StrutStyle?
-
Strut style forwarded to the underlying text rendering.
final
- style → TextStyle?
-
Text style applied to the rendered content.
final
- text → String
-
The text to display. Ignored as the initial source when stream is set
(the stream drives content instead).
final
- textAlign → TextAlign?
-
Horizontal alignment of the rendered text.
final
- textDirection → TextDirection?
-
Text direction override. When
null, direction is inferred (including automatic RTL detection for Arabic content).final - textHeightBehavior → TextHeightBehavior?
-
Height behavior applied to the rendered text.
final
- textScaler → TextScaler?
-
Scales the rendered text size.
final
- textWidthBasis → TextWidthBasis?
-
How to measure the width of the rendered text.
final
- trailingFadeEnabled → bool
-
Whether to show a trailing gradient fade at the bottom edge while text is
streaming. The fade animates away when streaming completes (using
fadeInDuration / fadeInCurve for the dismiss animation).
final
- typingSpeed → Duration
-
How long to wait between revealing each character (or word/chunk,
depending on wordByWord and chunkSize).
final
- wordByWord → bool
-
Whether to reveal text one word at a time instead of one character (or
chunkSize characters) at a time.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< StreamingText> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited