vyuh_diagram_codec_json 3.5.1
vyuh_diagram_codec_json: ^3.5.1 copied to clipboard
Save and load Vyuh Diagram documents as JSON in pure Dart. Round-trips shapes, text and connectors, plus content owned by installed extensions.
vyuh_diagram_codec_json
Save and load Vyuh Diagram documents as JSON, in pure Dart.
Vyuh Diagram · Docs · Examples · API reference
Turn a diagram document into JSON text and back. The codec runs on the Dart VM and on the web, so the same file opens in an app, on a server or in a script.
What you get #
- A stable format: schema
vyuh.diagram, version 1. The codec writes version 1 and reads only version 1. - Everything in the document: shapes, text, connectors, styles and geometry.
- Extension content: content and text attributes owned by installed extensions persist through their own codecs, so reopen a drawing with the same extensions installed.
Flutter already re-exports this codec, so Flutter apps seldom add it directly.
Install #
dart pub add vyuh_diagram_codec_json
Save and restore #
With a controller, the installed extensions supply their codecs:
import 'package:vyuh_diagram_codec_json/vyuh_diagram_codec_json.dart';
import 'package:vyuh_diagram_core/vyuh_diagram_core.dart';
final controller = DiagramController();
controller.createShape(Shapes.rectangle, at: DiagramPoint.zero, text: 'Hello');
final json = controller.save(DiagramJsonCodec.new);
controller.load(json, format: DiagramJsonCodec.new);
Without a controller, encode and decode a document directly:
import 'package:vyuh_diagram_types/vyuh_diagram_types.dart';
const codec = DiagramJsonCodec(DiagramModelCodecs.empty());
final json = codec.encode(document);
final restored = codec.decode(json);
Learn more #
Where this fits #
Vyuh Diagram is a diagram editor you embed in your own app. Five packages are open source (Apache-2.0) on pub.dev:
| Package | What it is |
|---|---|
vyuh_diagram_types |
Immutable document model and geometry. |
vyuh_diagram_core |
Controller, edits and history, in pure Dart. |
vyuh_diagram_flutter |
Flutter canvas, input and rendering. |
vyuh_diagram_codec_json |
Save and load diagrams as JSON. |
vyuh_diagram_codec_svg |
Export diagrams as SVG; import SVG shapes. |
Commercial extensions add the editor, shape libraries, automatic layout, rich text, tables, a minimap and more. They come from pub.vyuh.tech; see package access and the full package list.
License #
Apache License, Version 2.0 (text). Third-party materials keep their own licenses; see the notices shipped in this package.