vyuh_diagram_codec_json 3.2.0 copy "vyuh_diagram_codec_json: ^3.2.0" to clipboard
vyuh_diagram_codec_json: ^3.2.0 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.

example/main.dart

import 'package:vyuh_diagram_codec_json/vyuh_diagram_codec_json.dart';
import 'package:vyuh_diagram_types/vyuh_diagram_types.dart';

/// Encodes a diagram document to JSON and decodes it again.
///
/// With a `DiagramController`, pass `DiagramJsonCodec.new` to `save` and
/// `load` instead, so installed extensions persist the content they own.
void main() {
  final document = DiagramDocument(
    id: 'plan',
    revision: 0,
    elements: [
      ShapeElement(
        id: 'start',
        type: Shapes.rectangle,
        frame: const DiagramRect.fromLTWH(0, 0, 160, 80),
      ),
    ],
  );

  const codec = DiagramJsonCodec(DiagramModelCodecs.empty());
  final json = codec.encode(document);
  final restored = codec.decode(json);

  // ignore: avoid_print
  print(
    '${json.length} characters; restored ${restored.elements.length} shape',
  );
}
0
likes
0
points
890
downloads

Documentation

Documentation

Publisher

verified publishervyuh.tech

Weekly Downloads

Save and load Vyuh Diagram documents as JSON in pure Dart. Round-trips shapes, text and connectors, plus content owned by installed extensions.

Homepage

Topics

#diagram #json #serialization #codec #flowchart

License

unknown (license)

Dependencies

vyuh_diagram_types

More

Packages that depend on vyuh_diagram_codec_json