Controller lifetime
Loading interactive example…Open in new tab ↗
Move a card, choose Unmount, then Dispose controller. Mount creates a new canvas controller that joins the same diagram as the same participant. Your content and undo history remain; Undo restores the move. Reset example disposes the controller and the diagram and creates a fresh drawing.
The host waits for the canvas to unmount before disposing its controller. The diagram is owned separately, so disposing a controller that joined it releases its presentation resources and subscriptions without destroying the document. All resources are disposed when this example leaves the widget tree.
The host creates its diagram with FlutterDiagramTextLayoutEngine, so every controller that joins it shares the same canonical shaped text geometry.
This is an ownership example, not independent multi-user collaboration. A controller that rejoins with the same participant id continues that participant's undo history. Ordinary hosts can instead use DiagramController(document: ...) and dispose that controller when finished.
See Ownership and Collaboration.
Application ownership
For a normal application, keep one controller in your host state. Unmounting the canvas retains that controller's content and history. Dispose it when the host ends:
dart
final controller = DiagramController(
document: DiagramDocument(id: 'drawing', revision: 0, elements: []),
);
// Mount and unmount a DiagramCanvas(controller: controller) as needed.
// When the host is finished and the canvas has unmounted:
controller.dispose();To retain a drawing beyond any one controller, create a Diagram yourself and join it with DiagramController(diagram: diagram, participant: const DiagramParticipant(id: 'canvas', name: 'Canvas')). Disposing that controller leaves the diagram alive; dispose the diagram when the host ends. This uses the same public verbs and canonical drawing in pure Dart and Flutter.