DrawingController class
The core controller for the drawing engine.
Manages all drawing state, gesture handling, undo/redo, and shape manipulation. Uses ChangeNotifier to efficiently notify listeners of state changes.
Usage
final controller = DrawingController();
// ... use with DrawingCanvas widget
controller.dispose();
- Inheritance
-
- Object
- ChangeNotifier
- DrawingController
Constructors
- DrawingController({DrawingConfig config = const DrawingConfig()})
Properties
- activeHandle → ResizeHandle
-
no setter
- canRedo → bool
-
no setter
- canUndo → bool
-
no setter
- canvasOffset ↔ Offset
-
getter/setter pair
- canvasScale ↔ double
-
getter/setter pair
- config → DrawingConfig
-
Engine configuration.
final
- currentShape ↔ ShapeType
-
getter/setter pair
- currentTool ↔ Tool
-
getter/setter pair
- drawMode ↔ DrawMode
-
getter/setter pair
-
drawnShapes
→ List<
DrawnShape> -
Mutable shapes list — use for direct manipulation (e.g., adding shapes).
Prefer addShape, removeShape for tracked operations.
no setter
- endPoint → Offset?
-
no setter
- eraserPosition → Offset?
-
no setter
- handleRadius → double
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- interactionMode ↔ InteractionMode
-
getter/setter pair
- isDrawing → bool
-
no setter
- isResizing → bool
-
no setter
- isSnappingEnabled → bool
-
no setter
- measurementEnd → Offset?
-
no setter
- measurementStart → Offset?
-
no setter
- measurementValue → String
-
no setter
- onSelectionChanged ↔ void Function(DrawnShape? shape)?
-
Called when a shape is selected or deselected.
getter/setter pair
- onShapeAdded ↔ void Function(DrawnShape shape)?
-
Called when a shape is added.
getter/setter pair
- onShapesCleared ↔ VoidCallback?
-
Called when shapes are cleared.
getter/setter pair
- onShapeTextEditRequested ↔ void Function(DrawnShape shape)?
-
Called when a shape's text needs editing.
getter/setter pair
- onTextInputRequested ↔ void Function(Offset position)?
-
Called when the engine needs text input (e.g., the Text tool was tapped).
getter/setter pair
- redoCount → int
-
no setter
- revision → int
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- selectedShape ↔ DrawnShape?
-
getter/setter pair
-
shapes
→ List<
DrawnShape> -
Read-only view of the current shapes.
no setter
- showGrid ↔ bool
-
getter/setter pair
- showPropertyPanel ↔ bool
-
getter/setter pair
- startPoint → Offset?
-
no setter
- strokeColor ↔ Color
-
getter/setter pair
- strokeWidth ↔ double
-
getter/setter pair
-
suggestedShapes
→ List<
ShapeType> ? -
no setter
- suggestionPosition → Offset?
-
no setter
- undoCount → int
-
no setter
Methods
-
acceptSuggestion(
ShapeType type) → void - Accepts a shape suggestion — replaces the last freehand with the recognized shape.
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
addShape(
DrawnShape shape) → void - Adds a shape and notifies listeners.
-
clearAll(
) → void - Clears all shapes (saves undo state first).
-
deleteSelectedShape(
) → void - Deletes the currently selected shape.
-
discardSuggestion(
) → void - Discards the current shape suggestion.
-
dispose(
) → void -
Discards any resources used by the object. After this is called, the
object is not in a usable state and should be discarded (calls to
addListener will throw after the object is disposed).
override
-
duplicateSelectedShape(
) → void - Duplicates the currently selected shape with an offset.
-
exportAsPNG(
GlobalKey< State< canvasKey, {int pixelRatio = 1}) → Future<StatefulWidget> >Uint8List?> - Exports the canvas as a PNG byte array.
-
flipHorizontal(
) → void - Flips the selected shape horizontally.
-
flipVertical(
) → void - Flips the selected shape vertically.
-
handleLongPressStart(
Offset pos) → void - Called on long-press start.
-
handlePanEnd(
) → void - Called when a pan gesture ends.
-
handlePanStart(
Offset pos) → void - Called when a pan gesture starts.
-
handlePanUpdate(
Offset pos, Offset delta) → void - Called when a pan gesture updates.
-
handleScaleUpdate(
double scale, Offset focalPoint) → void - Handles pinch-to-zoom gestures.
-
handleTapDown(
Offset pos) → void - Called on tap down events.
-
layerDown(
) → void - Moves the selected shape down one layer.
-
layerUp(
) → void - Moves the selected shape up one layer.
-
loadFromJson(
String jsonString) → void - Loads shapes from a JSON string.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
redo(
) → void - Redoes the last undone action.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
removeShape(
DrawnShape shape) → void - Removes a shape and notifies listeners.
-
resetView(
) → void -
rotateSelectedShape(
) → void - Rotates the selected shape by 45°.
-
saveStateForUndo(
) → void - Stores the current shapes for undo. Call before mutations.
-
toggleSnapping(
) → void - Toggles magnetic snapping on/off.
-
toJson(
) → String - Serializes all shapes to a JSON string.
-
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → void - Undoes the last action.
-
updateState(
) → void - Triggers a manual refresh of the engine UI.
-
zoomIn(
) → void - Zoom controls.
-
zoomOut(
) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited