DrawImageLayer class
Free-draw layer with four brush types (pen / marker / neon / eraser), per-brush thickness, velocity-aware width, and an optional arrow toggle on pen. Strokes operate in image-space; the gesture surface translates viewport coords via toImageSpace.
The viewport-fitting matrix lives on the host (ComposeEntry); the
layer is told the current camera at paint time, and its scale is
captured at gesture-start time to size brush thickness in image-space.
- Mixed-in types
- Available extensions
Constructors
- DrawImageLayer({required Image image})
-
Draws over
image, which the caller owns.
Properties
-
brushColors
→ Map<
BrushType, Color> -
Per-brush color memory. The layer's currentColor is a view onto
this map at currentBrush; switching brushes loads that brush's
remembered color.
final
- currentBrush ↔ BrushType
-
The selected brush.
getter/setter pair
- currentColor → Color
-
The selected brush's colour.
no setter
-
currentPoints
→ List<
StrokePoint> -
The samples of the stroke in flight.
final
- currentThickness → double
-
The selected brush's thickness in logical screen pixels.
no setter
- disposed → bool
-
Whether dispose has already run.
no setterinherited
- exportSize → Size
-
This layer's intrinsic export size — typically the source image's
natural dimensions.
no setteroverride
- hasAppliedEdits → bool
-
True if at least one stroke has been committed (used by
ComposeEntry to decide whether to rasterise on submit).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether there is at least one active listener.
no setterinherited
- image → Image
-
The source image.
final
- imageSize → Size
-
image's size in pixels.
latefinal
- normalizedThickness ↔ double
-
The selected brush's thickness, 0 to 1 of its width range.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
strokes
→ List<
Stroke> -
The committed strokes, oldest first.
final
Methods
-
addDispose(
VoidCallback callback) → void -
Registers a disposal
callback. Ignored if already disposed.inherited -
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object notifies its listeners.
inherited
-
addPoint(
Offset imagePoint) → bool -
Adds
imagePointto the stroke in flight. False when the sample is dropped for coming too soon or too close to the last one. -
beginStroke(
Offset imagePoint, {double cameraScale = 1.0}) → void -
Starts a stroke at
imagePoint, sizing it for a camera atcameraScale. -
cancelStroke(
) → void - Discard the in-flight stroke's buffered points WITHOUT committing them as a Stroke. Used when the gesture system needs to switch modes mid-stroke (e.g. a second finger lands and we pivot from drawing to pan/zoom).
-
completeAnimations(
) → void - Cancel any in-flight drying / arrow animation and snap every stroke to its fully-committed shape (tail factor 1.0, arrow progress 1.0).
-
dispose(
) → void -
Releases whatever this object holds. Calling it twice is an error.
inherited
-
disposeBy(
Dispose disposer) → void -
Available on Disposable, provided by the DisposableDisposerExtension extension
Adds this object's dispose to another Dispose collector. -
driveSnapshotRevert(
double t) → void - Interactive counterpart of restoreSnapshotAnimated's fade: the draw screen maps swipe-back progress here so strokes drawn this session fade with the finger (t = 1 fully visible, 0 gone). An aborted swipe drives t back to 1 — full opacity, nothing to release. Committed strokes from before the snapshot are unaffected.
-
endStroke(
) → void - Commits the stroke in flight and starts the drying and arrow animations its brush has.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Notifies all registered listeners.
inherited
-
paintExport(
Canvas canvas, Size size) → void -
Paint into the export canvas.
sizeis the editor-wide export size (max over all exporters), so layers must position themselves accordingly.override -
paintSourceAndStrokes(
Canvas canvas) → void - Paint source image + all strokes (committed + in-flight) at the current canvas origin. Caller has set up the canvas transform (e.g. camera + image-space ops); we just deposit our content. Used by both the layer's own paintViewport and by composed-scene painters that render the source × strokes pipeline inside a crop transform.
-
paintStrokesOnly(
Canvas canvas, Size size) → void -
Paint just the buffered strokes — no source image. Used by the
compose-pipeline composer (
ComposeEntry._composeLayers) when an upstream stage has already painted the image; we want to stack strokes on top without redrawing the source. Strokes are in source-space coordinates so they line up with whatever the upstream painted at the same dims. -
paintViewport(
Canvas canvas, Size size, {required Matrix4 camera}) → void -
Paints the layer into a viewport of
sizethroughcamera.override -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that the
object notifies.
inherited
-
restoreSnapshot(
) → void - Restore the layer to the last saveSnapshot. No-op if none saved. Any in-flight stroke is discarded.
-
restoreSnapshotAnimated(
) → Future< void> -
Like restoreSnapshot but fades out the strokes added during the
current session before clearing them, so canceling a draw session
is a smooth reverse instead of an instant disappear. Returns a
Future that completes when the fade + snap finishes —
DrawScreen._cancelfires this unawaited and then pops, so the fade overlaps with the screen pop transition. -
saveSnapshot(
) → void - Capture current state for later restoreSnapshot. The strokes list is copied (shallow — stroke objects themselves are settled references). Per-brush color + thickness maps are deep-copied.
-
setBrushType(
BrushType type) → void -
Selects
type. -
setCurrentColor(
Color color) → void - Sets the selected brush's colour.
-
subscribe(
VoidCallback callback) → VoidCallback -
Available on Listenable, provided by the ListenableExtension extension
Addscallbackas listener and returns a function to remove it. -
toString(
) → String -
A string representation of this object.
inherited
-
undo(
) → void - Removes the newest committed stroke.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
toImageSpace(
Offset viewport, Matrix4 camera) → Offset -
Convert a viewport-space pointer position to image-space using the
host
camera(uniform scale + translate, no rotate).