CanvasEditorController class
Primary Host API for the Canvas Editor Engine.
Create one controller, pass it to CanvasEditorWidget, and build Host UI (toolbars, panels) around stateStream / command methods.
- Live UI → listen to stateStream (updates every gesture frame).
- Autosave / sync → onDocumentChanged (fires on committed changes only).
Constructors
-
CanvasEditorController({DesignDocument? initialDocument, CanvasImageProvider? imageProvider, List<
CustomNodeType< ? customNodeTypes, void onDocumentChanged(DesignDocument doc)?})DesignNode> > - Creates a controller.
Properties
- customNodeRegistry → CustomNodeRegistry
-
Custom Node types scoped to this Controller.
final
- document → DesignDocument
-
Current Design Document (latest, including mid-gesture previews).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- imageProvider → CanvasImageProvider?
-
Resolves
assetIdimage references (CDN URLs, assets, etc.).final - onDocumentChanged → void Function(DesignDocument doc)?
-
Called when a Design Document change is committed (gesture end, add/delete,
history session commit, undo/redo, load) — not on every mid-drag frame.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- state → CanvasEditorState
-
Current public editor snapshot (selection, undo flags, document).
no setter
-
stateStream
→ Stream<
CanvasEditorState> -
Live Engine state for Host UI. Emits on selection and every document mutation,
including mid-drag frames.
no setter
Methods
-
addImageNode(
{required String localPath, bool select = true}) → void - Adds an image Node from a local file path.
-
addTextNode(
{String? text, Offset? position, bool select = true}) → void -
Adds a text Node. Defaults to centered placeholder text when
text/positionare omitted. -
beginHistorySession(
) → void - Starts a history session so many live property updates become one undo step.
-
bringForward(
String nodeId) → void -
Moves
nodeIdone step up in z-order. -
bringToFront(
String nodeId) → void -
Moves
nodeIdabove all other Nodes. -
clearBackgroundImage(
) → void - Clears Background Fill image and restores the solid color.
-
commitHistorySession(
) → void - Ends a beginHistorySession and pushes one undo entry when the document changed.
-
deleteNode(
String nodeId) → void -
Deletes the Node with
nodeId. -
dispose(
) → void -
Releases streams and internal Engine resources. Call from Host
dispose. -
documentFromJson(
Map< String, dynamic> json) → DesignDocument - Parses JSON with this Controller's customNodeRegistry.
-
exportToPng(
{double pixelRatio = 2.0}) → Future< Uint8List> - Renders the current Design Document to PNG bytes (same pipeline as the live canvas).
-
loadDocument(
DesignDocument doc) → void - Replaces the current Design Document.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
redo(
) → void - Redoes the last undone change.
-
selectNode(
String? nodeId) → void -
Selects
nodeId, or clears selection whennull. -
sendBackward(
String nodeId) → void -
Moves
nodeIdone step down in z-order. -
sendToBack(
String nodeId) → void -
Moves
nodeIdbelow all other Nodes (above Background Fill). -
setBackgroundImage(
{String? localPath, String? assetId}) → void -
Sets Background Fill image. Pass either
localPathorassetId, not both. -
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → void - Undoes the last committed change.
-
updateBackground(
String colorHex, {bool recordUndo = true}) → void -
Sets Background Fill to a solid ARGB hex color (e.g.
'#FFFFFFFF'). -
updateTextContent(
String nodeId, String text, {bool recordUndo = true}) → void - Updates text content and reflows height. See updateTextStyle for undo coalescing.
-
updateTextStyle(
String nodeId, {double? fontSize, String? textColor, String? fontFamily, int? fontWeight, double? lineHeight, double? letterSpacing, String? textAlign, bool recordUndo = true}) → void - Updates text style fields and reflows height to fit wrapped text (width held).
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited