Session lifetime
Loading interactive example…Open in new tab ↗
Move a card, choose Unmount, then Dispose session. Mount creates a new canvas session attached to the same source session. Your content and undo history remain; Undo restores the move. Reset example disposes both sessions and creates a fresh drawing.
The host waits for the canvas to unmount before disposing its session. The source session is owned separately, so disposing its Flutter adapter 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 source session with FlutterDiagramTextLayoutEngine, so wrapping or replacing the session retains the same canonical shaped text geometry.
This is an ownership example, not independent multi-user collaboration. Borrowed sessions share selection, history and interaction admission. Ordinary hosts can instead use DrawingSession(document: ...) and dispose that session when finished.
See Ownership and Collaboration.
Application ownership
For a normal application, keep one session in your host state. Unmounting the canvas retains that session's content and history. Dispose it when the host ends:
dart
final session = DrawingSession(
document: DiagramDocument(id: 'drawing', revision: 0, elements: []),
);
// Mount and unmount a DrawingCanvas(session: session) as needed.
// When the host is finished and the canvas has unmounted:
session.dispose();To retain a drawing across Flutter adapter replacements, create a source session with the pure Dart package and attach it using DrawingSession.fromSession(source). Dispose the canvas adapter before disposing its source. This uses the same public commands and canonical drawing in both environments.