Mermaid diagrams
vyuh_document_mermaid renders Mermaid diagrams natively in pure Dart via mermaid_core — no WebView, no browser DOM, deterministic pagination, and crisp vector output on screen and in PDF.
- Optional heavy plugin: Separate package pair so base apps pay zero bundle cost
- Pure-Dart package:
package:vyuh_document_mermaid/vyuh_document_mermaid.dart - Flutter package:
package:vyuh_document_mermaid_flutter/vyuh_document_mermaid_flutter.dart - Action namespace:
MermaidActions(insert,edit)
Installation
yaml
dependencies:
vyuh_document_mermaid:
hosted: https://pub.vyuh.tech
version: ^0.90.0
vyuh_document_mermaid_flutter:
hosted: https://pub.vyuh.tech
version: ^0.90.0sh
flutter pub add vyuh_document_mermaid vyuh_document_mermaid_flutter --hosted-url https://pub.vyuh.techQuick example
dart
import 'package:vyuh_document_flutter/editor.dart';
import 'package:vyuh_document_mermaid_flutter/vyuh_document_mermaid_flutter.dart';
final config = documentConfiguration.withElements([MermaidDiagram.element]);
final controller = DocumentEditorController(
document: Document.of(config, [
MermaidDiagram('''
flowchart LR
Author[Document Model] --> Layout[Pure-Dart Layout]
Layout --> Flutter[Flutter Editor]
Layout --> PDF[Vector PDF]
'''),
]),
extensions: [
...DocumentEditorElements.defaults,
const MermaidEditorExtension(),
],
);What you can configure
| Property / Capability | Purpose |
|---|---|
source | Canonical Mermaid source text (flowchart, sequenceDiagram, classDiagram, stateDiagram-v2, erDiagram, gantt, and more) |
| Frame & sizing | Block width, alignment, border/background GraphicFrameStyle, and frame orientation |
| Live split/inline source editor | Click or double-click the diagram to edit Mermaid syntax with live re-layout and syntax diagnostics |
| Localization | Customize Mermaid editor UI labels via MermaidDocumentLocalizations |
Actions & commands
| Action ID / Command | Effect |
|---|---|
MermaidActions.insert | Insert a new Mermaid diagram block |
MermaidActions.edit | Open the Mermaid source editor for the active diagram |
SetDiagramSource | Pure-Dart command updating diagram source text canonically |
Restricting usage
- Read-only rendered diagrams: In
DocumentInteractionMode.readOnly(or whenMermaidActions.editis gated byDocumentPolicy), diagrams render crisply as vectors while preventing source edits.
See the full Mermaid coverage matrix.
Format parity
| DOCX | HTML | Markdown | |
|---|---|---|---|
| Embedded high-resolution diagram graphic with source preservation | Direct vector PDF paths & shaped labels | Embedded SVG + source metadata | Fenced ```mermaid code block |