PainterController class Null safety

Controller used to control a FlutterPainter widget.

Available Extensions


PainterController({PainterSettings settings = const PainterSettings(), List<Drawable>? drawables = const [], BackgroundDrawable? background})
Create a PainterController.
PainterController.fromValue(PainterControllerValue value)
Create a PainterController from a PainterControllerValue.


background BackgroundDrawable?
Setting this will notify all the listeners of this PainterController that they need to update (it calls notifyListeners). For this reason, this value should only be set between frames, e.g. in response to user actions, not during the build, layout, or paint phases.
canRedo bool
Whether a redo operation can be performed or not.
canUndo bool
Whether an undo operation can be performed or not.
events Stream<PainterEvent>
The stream of PainterEvents dispatched from this controller.
hashCode int
The hash code for this object.
hasListeners bool
Whether any listeners are currently registered.
painterKey GlobalKey<State<StatefulWidget>>
This key will be used by the FlutterPainter widget assigned this controller.
performedActions Queue<ControllerAction>
Queues used to track the actions performed on drawables in the controller. This is used to undo and redo actions.
read / write
runtimeType Type
A representation of the runtime type of the object.
selectedObjectDrawable ObjectDrawable?
The currently selected object drawable.
transformationController TransformationController
This controller will be used by the InteractiveViewer in FlutterPainter to notify children widgets of transformation changes.
unperformedActions Queue<ControllerAction>
Queues used to track the actions performed on drawables in the controller. This is used to undo and redo actions.
read / write
value PainterControllerValue
The current value stored in this notifier.
read / writeinherited


addDrawables(Iterable<Drawable> drawables, {bool newAction = true}) → void
Add the drawables to the controller value drawables.
addImage(Image image, [Size? size]) → void
Adds an ImageDrawable to the center of the painter.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
addText() → void
Dispatches a AddTextPainterEvent on events stream.
clearDrawables({bool newAction = true}) → void
Removes all drawables from the controller value.
deselectObjectDrawable({bool isRemoved = false}) → void
Deselects the object drawable from the drawables.
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).
groupDrawables({bool newAction = true}) → void
Groups all drawables in the controller into one drawable.
insertDrawables(int index, Iterable<Drawable> drawables, {bool newAction = true}) → void
Inserts the drawables to the controller value drawables at the provided index.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
notifyListeners() → void
Call all the registered listeners.
redo() → void
Redoes the last undone action. The redo operation can be undone.
removeDrawable(Drawable drawable, {bool newAction = true}) bool
Removes the first occurrence of drawable from the controller value.
removeLastDrawable({bool newAction = true}) → void
Removes the last drawable from the controller value.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
renderImage(Size size) Future<Image>
Renders the background and all other drawables to a ui.Image object.
replaceDrawable(Drawable oldDrawable, Drawable newDrawable, {bool newAction = true}) bool
Replace oldDrawable with newDrawable in the controller value.
selectObjectDrawable(ObjectDrawable? drawable) → void
Selects an object drawable from the list of drawables.
toString() String
A string representation of this object.
undo() → void
Undoes the last action performed on drawables. The action can later be redone.


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

Static Methods

of(BuildContext context) PainterController
Uses the PainterControllerWidget inherited widget to fetch the PainterController instance in this context. This is used internally in the library to fetch the controller at different widgets.