CanvasController class

Controller for Flint Canvas drawing.

This server-safe implementation stores retained objects but does not draw. Browser builds bind the controller to the rendered canvas element.

Constructors

CanvasController({CanvasSelectCallback? onSelect, CanvasChangeCallback? onChange, CanvasObjectsCallback? onMove, CanvasObjectsCallback? onResize, CanvasObjectsCallback? onRotate, CanvasTextEditCallback? onTextEdit, CanvasPointerCallback? onPointerDown, CanvasPointerCallback? onPointerUp, CanvasPointerCallback? onHover, CanvasPointerCallback? onDragStart, CanvasPointerCallback? onDragEnd, CanvasPointerCallback? onResizeStart, CanvasPointerCallback? onResizeEnd, CanvasPointerCallback? onRotateStart, CanvasPointerCallback? onRotateEnd, CanvasHistoryCallback? onUndo, CanvasHistoryCallback? onRedo, bool snapToGrid = false, double gridSize = 8, bool snapToObjects = false, double snapThreshold = 6, int maxHistoryEntries = 100, CanvasObjectConstraints constraints = const CanvasObjectConstraints(), bool showGrid = false, bool showRulers = false, bool showSnapGuides = true})
Creates a canvas controller.

Properties

canRedo → bool
Whether redo history is available.
no setter
canUndo → bool
Whether undo history is available.
no setter
canvasHeight → double?
Retained canvas height constraint.
no setter
canvasWidth → double?
Retained canvas width constraint.
no setter
constraints → CanvasObjectConstraints
Object editing constraints.
final
gridSize → double
Grid size used by snapSelectedToGrid and drag snapping.
final
hashCode → int
The hash code for this object.
no setterinherited
isAttached → bool
Whether the controller is attached to a browser canvas.
no setter
layerItems → List<CanvasLayerItem>
Layer-panel view of retained objects, ordered from front to back.
no setter
maxHistoryEntries → int
Maximum undo or redo entries to keep.
final
objects → List<CanvasObject>
Retained canvas objects.
no setter
onChange → CanvasChangeCallback?
Fires after retained canvas scene data changes.
final
onDragEnd → CanvasPointerCallback?
Fires when object dragging ends.
final
onDragStart → CanvasPointerCallback?
Fires when object dragging starts.
final
onHover → CanvasPointerCallback?
Fires when the hovered object changes.
final
onMove → CanvasObjectsCallback?
Fires after selected objects move.
final
onPointerDown → CanvasPointerCallback?
Fires on browser pointer down.
final
onPointerUp → CanvasPointerCallback?
Fires on browser pointer up.
final
onRedo → CanvasChangeCallback?
Fires after redo succeeds.
final
onResize → CanvasObjectsCallback?
Fires after selected objects resize.
final
onResizeEnd → CanvasPointerCallback?
Fires when selection-handle resizing ends.
final
onResizeStart → CanvasPointerCallback?
Fires when selection-handle resizing starts.
final
onRotate → CanvasObjectsCallback?
Fires after selected objects rotate.
final
onRotateEnd → CanvasPointerCallback?
Fires when selection-handle rotation ends.
final
onRotateStart → CanvasPointerCallback?
Fires when selection-handle rotation starts.
final
onSelect → CanvasObjectsCallback?
Fires when selected objects change.
final
onTextEdit → CanvasTextEditCallback?
Optional text edit provider used by browser double-click editing.
final
onUndo → CanvasChangeCallback?
Fires after undo succeeds.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
selectedBounds → CanvasBounds?
Bounds for the currently selected object.
no setter
selectedObject → CanvasObject?
Currently selected object.
no setter
selectedObjectId → String?
Currently selected object id.
no setter
selectedObjectIds → List<String>
Currently selected object ids.
no setter
selectedObjects → List<CanvasObject>
Currently selected objects.
no setter
showGrid → bool
Whether browser canvas builds should draw a grid.
final
showRulers → bool
Whether browser canvas builds should draw rulers.
final
showSnapGuides → bool
Whether browser canvas builds should draw snap guides.
final
snapGuides → List<CanvasGuide>
Active snap guides from the latest snap operation.
no setter
snapThreshold → double
Distance threshold for object edge/center snapping.
final
snapToGrid → bool
Whether movement should snap selected objects to gridSize.
final
snapToObjects → bool
Whether movement should snap selected objects to other object edges/centers.
final

Methods

add(CanvasObject object) → void
Adds an object to the retained canvas scene.
addCircle(CanvasCircle circle) → void
Adds a circle object.
addImage(CanvasImageObject image) → void
Adds an image object.
addLine(CanvasLine line) → void
Adds a line object.
addRect(CanvasRect rect) → void
Adds a rectangle object.
addText(CanvasTextObject text) → void
Adds a text object.
alignSelected(CanvasAlignment alignment) → bool
Aligns selected objects inside the selection bounds.
beginHistoryBatch() → void
Starts batching subsequent changes into one undo entry.
bringForward(String id) → bool
Moves an object one step forward in z order.
bringToFront(String id) → bool
Moves an object to the front of z order.
cancelHistoryBatch() → void
Cancels an active history batch without adding an undo entry.
clear() → void
Removes all retained objects and clears the canvas.
clearHistory() → void
Clears undo and redo history.
copySelected() → bool
Copies the selected object into the controller clipboard.
deleteSelected() → bool
Deletes the selected object.
detach() → void
Detaches from the browser canvas.
drawCircle(CanvasCircle circle) → void
Draws a circle immediately.
drawImage(CanvasImageObject image) → void
Draws an image immediately.
drawLine(CanvasLine line) → void
Draws a line immediately.
drawRect(CanvasRect rect) → void
Draws a rectangle immediately.
drawText(CanvasTextObject text) → void
Draws text immediately.
duplicateSceneJson() → Map<String, Object?>
Creates a duplicate JSON snapshot of the current scene.
duplicateSelected({double dx = 20, double dy = 20}) → List<CanvasObject>
Duplicates the selected objects and places them offset by dx, dy.
endHistoryBatch() → void
Finishes a history batch.
handleKeyboardCommand(String key, {bool control = false, bool meta = false, bool shift = false}) → bool
Handles a keyboard command for the selected canvas object.
hitTest(double x, double y) → CanvasObject?
Returns the topmost object at x, y.
importBackendJson(Map<String, Object?> json) → void
Loads scene JSON from a saved backend payload.
loadJson(Map<String, Object?> json) → void
Loads retained objects from JSON-friendly scene data.
moveBy(String id, double dx, double dy) → bool
Moves an object by dx, dy.
moveSelectedBy(double dx, double dy) → bool
Moves the selected object by dx, dy.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
nudgeSelected({double dx = 0, double dy = 0, bool largeStep = false}) → bool
Moves the selected object with keyboard-style step sizes.
objectById(String id) → CanvasObject?
Finds a retained object by id.
pasteCopied({double dx = 12, double dy = 12}) → List<CanvasObject>
Pastes copied objects and selects the pasted objects.
redo() → bool
Restores the next scene state after undo.
remove(String id) → bool
Removes a retained object by id.
renameObjectId(String currentId, String nextId) → bool
Renames an object's id for layer panels and app-level references.
render() → void
Redraws the retained scene.
resizeBy(String id, double dw, double dh) → bool
Resizes an object by dw, dh.
resizeSelectedBy(double dw, double dh) → bool
Resizes the selected object by dw, dh.
resizeSelectedFromHandle(CanvasSelectionHandle handle, double dx, double dy) → bool
Resizes the selected object from a visible selection handle.
rotateBy(String id, double degrees) → bool
Rotates an object by degrees.
rotateSelectedBy(double degrees) → bool
Rotates the selected object by degrees.
select(String? id) → bool
Selects an object by id.
selectAll() → bool
Selects all visible, unlocked objects on the canvas.
selectAt(double x, double y) → CanvasObject?
Selects the topmost object at x, y.
selectedToJson() → Map<String, Object?>
Exports selected retained objects as JSON-friendly scene data.
selectInBounds(CanvasBounds bounds) → bool
Selects all visible objects that intersect or are contained in bounds.
selectMany(Iterable<String> ids) → bool
Selects multiple objects by id.
sendBackward(String id) → bool
Moves an object one step backward in z order.
sendToBack(String id) → bool
Moves an object to the back of z order.
setCanvasSize(double width, double height) → void
Updates viewport dimensions for canvas-bound constraints.
setObjectHidden(String id, bool hidden) → bool
Hides or shows an object.
setObjectLocked(String id, bool locked) → bool
Locks or unlocks an object.
setObjectName(String id, String? name) → bool
Sets a display name for an object.
setRotation(String id, double degrees) → bool
Sets an object's rotation in degrees.
setSelectedFont({String? family, double? size, String? cssFont}) → bool
Updates font family/size for selected text objects.
setSelectedHidden(bool hidden) → bool
Hides or shows selected objects.
setSelectedLocked(bool locked) → bool
Locks or unlocks selected objects.
setSelectedRotation(double degrees) → bool
Sets all selected objects to degrees rotation.
snapSelectedToGrid([double? size]) → bool
Snaps selected objects to the nearest grid coordinates.
snapSelectedToObjects({double? threshold}) → bool
Snaps selected objects to nearby visible object edges or centers.
styleSelected({String? fill, CanvasImagePattern? pattern, String? stroke, double? lineWidth, String? font, bool clearFill = false, bool clearPattern = false, bool clearStroke = false}) → bool
Updates selected object style fields while preserving unspecified paint.
toDataUrl({String type = 'image/png', double? quality}) → String
Exports the canvas to a data URL.
toggleSelection(String id) → bool
Adds or removes id from the current selection.
toggleSelectionAt(double x, double y) → CanvasObject?
Toggles the topmost object at x, y in the current selection.
toJson() → Map<String, Object?>
Exports retained objects as JSON-friendly scene data.
toString() → String
A string representation of this object.
inherited
undo() → bool
Restores the previous scene state.
update(String id, CanvasObject object) → bool
Replaces the object with id.
updateObjectPaint(String id, CanvasPaint paint) → bool
Updates paint on one object.
updateSelectedPaint(CanvasPaint paint) → bool
Updates paint on selected, unlocked objects.
updateSelectedText(String text) → bool
Updates the selected text object when exactly one text object is selected.
updateText(String id, String text) → bool
Updates one text object's text.

Operators

operator ==(Object other) → bool
The equality operator.
inherited