MermaidDiagram class

A widget that renders Mermaid diagrams using pure Dart/Flutter

This widget parses Mermaid diagram syntax and renders it using Flutter's CustomPainter, without any WebView or external dependencies.

Example usage:

MermaidDiagram(
  code: '''
  graph TD
    A[Start] --> B{Decision}
    B -->|Yes| C[OK]
    B -->|No| D[Cancel]
  ''',
  style: MermaidStyle.dark(),
)
Inheritance

Constructors

MermaidDiagram({Key? key, required String code, MermaidStyle? style, double? width, double? height, void onNodeTap(String nodeId)?, void onError(String nodeId)?, Widget errorBuilder(BuildContext context, String error)?, Widget loadingBuilder(BuildContext context)?, MermaidResponsiveConfig? responsiveConfig, bool enableResponsive = true})
Creates a Mermaid diagram widget
const

Properties

code → String
The Mermaid diagram code
final
enableResponsive → bool
Whether to enable responsive layout (defaults to true)
final
errorBuilder → Widget Function(BuildContext context, String error)?
Builder for error state
final
hashCode → int
The hash code for this object.
no setterinherited
height → double?
Fixed height (if not provided, uses computed size)
final
key → Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder → Widget Function(BuildContext context)?
Builder for loading state
final
onError → void Function(String nodeId)?
Callback when parsing fails
final
onNodeTap → void Function(String nodeId)?
Callback when a node is tapped
final
responsiveConfig → MermaidResponsiveConfig?
Responsive configuration for different screen sizes
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
style → MermaidStyle?
Style configuration (defaults to light theme)
final
width → double?
Fixed width (if not provided, uses available space)
final

Methods

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