AnimatedMath class

A widget that renders a LaTeX math tex string with a reveal animation.

Example:

// Wipe in from the left over 700ms (the default).
AnimatedMath(r'\int_0^1 x^2 \, dx')

// Fade the whole thing in.
AnimatedMath(r'E = mc^2', mode: MathAnimationMode.fadeIn)

// Drive it yourself with an external controller (replays, scrubbing, …).
AnimatedMath(r'a^2 + b^2 = c^2', controller: myController)

Playback

Sizing, color, and error handling match Math.

Inheritance

Constructors

AnimatedMath(String tex, {Key? key, MathAnimationMode mode = MathAnimationMode.leftToRight, Duration duration = const Duration(milliseconds: 700), Duration? stepDuration, Curve curve = Curves.easeOutCubic, bool autoPlay = true, AnimationController? controller, bool displayMode = false, double? fontSize, Color? color, Widget onError(BuildContext context, Object error)?, bool throwOnError = false, VoidCallback? onCompleted})
Creates an AnimatedMath widget for the LaTeX source tex.
const

Properties

autoPlay bool
Whether the internal controller plays automatically on first build and on tex/mode changes. Ignored when an external controller is supplied.
final
color Color?
The base text color. When null, the ambient DefaultTextStyle color is used (falling back to opaque black).
final
controller AnimationController?
An optional external controller (0 → 1) driving the reveal. When provided, the caller owns its lifecycle and duration/autoPlay are ignored.
final
curve Curve
Easing applied to the reveal progress. Defaults to Curves.easeOutCubic. Ignored (forced linear) when stepDuration is set.
final
displayMode bool
Display vs inline math, mirroring KaTeX's displayMode.
final
duration Duration
Duration of the whole reveal when using the internal controller. Ignored when stepDuration is set, or when an external controller is supplied.
final
fontSize double?
Base size in logical pixels per em. Defaults to kDefaultMathFontSize when null.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mode MathAnimationMode
How the formula is revealed. Defaults to MathAnimationMode.leftToRight.
final
onCompleted VoidCallback?
Called once each time the reveal animation completes (reaches 1.0). Useful for chaining reveals or kicking off follow-on work.
final
onError Widget Function(BuildContext context, Object error)?
Builder invoked to render a fallback when parsing/building throws and throwOnError is false. When null, the raw tex is shown in KaTeX's error red.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
stepDuration Duration?
When set, the reveal is paced one element per stepDuration — the total duration becomes elementCount × stepDuration and a linear curve is used, so elements appear at a steady rate (e.g. Duration(seconds: 1) ⇒ one element per second). Overrides duration and curve. Has no effect with MathAnimationMode.fadeIn (which fades the whole formula at once) or an external controller.
final
tex String
The LaTeX math source to render (e.g. r'\frac{a}{b}').
final
throwOnError bool
Whether to rethrow a parse/build error out of build (false by default).
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<AnimatedMath>
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