mermaid_flutter 0.7.0
mermaid_flutter: ^0.7.0 copied to clipboard
Native Flutter renderer for mermaid_core: TextPainter text measurement and a CustomPainter that paints the mermaid render scene directly. 28 diagram types.
example/mermaid_flutter_example.dart
// Shows a Mermaid flowchart in a pan-and-zoom view, painted natively with
// Flutter. Tap a node to center it.
//
// Run from an app that depends on mermaid_flutter, or copy this file into
// `lib/main.dart` of a new Flutter project.
import 'package:flutter/material.dart';
import 'package:mermaid_flutter/mermaid_flutter.dart';
void main() => runApp(const ExampleApp());
const _source = '''
graph TD
A[Start] --> B{Is it working?}
B -->|Yes| C[Ship it]
B -->|No| D[Debug]
D --> B
C --> E[Celebrate]
''';
class ExampleApp extends StatefulWidget {
const ExampleApp({super.key});
@override
State<ExampleApp> createState() => _ExampleAppState();
}
class _ExampleAppState extends State<ExampleApp> {
final _controller = MermaidViewController();
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('mermaid_flutter')),
body: MermaidView(
source: _source,
controller: _controller,
onNodeTap: (id, _) => _controller.centerOnNode(id),
errorBuilder: (context, error) => Center(child: Text('$error')),
),
),
);
}
}