SnapshotPainter class Null safety

A painter used to paint either a snapshot or the child widgets that would be a snapshot.

The painter can call notifyListeners to have the SnapshotWidget re-paint (re-using the same raster). This allows animations to be performed without re-snapshotting of children. For certain scale or perspective changing transforms, such as a rotation, this can be significantly faster than performing the same animation at the widget level.

By default, the SnapshotWidget includes a delegate that draws the child raster exactly as the child widgets would have been drawn. Nevertheless, this can also be used to efficiently transform the child raster and apply complex paint effects.

The following method shows how to efficiently rotate the child raster.
link
void paint(PaintingContext context, Offset offset, Size size, ui.Image image, double pixelRatio) {
  const double radians = 0.5; // Could be driven by an animation.
  final Matrix4 transform = Matrix4.rotationZ(radians);
  context.canvas.transform(transform.storage);
  final Rect src = Rect.fromLTWH(0, 0, image.width.toDouble(), image.height.toDouble());
  final Rect dst = Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height);
  final Paint paint = Paint()
    ..filterQuality = FilterQuality.low;
  context.canvas.drawImageRect(image, src, dst, paint);
}

Inheritance

Constructors

SnapshotPainter()

Properties

hashCode int
The hash code for this object.
read-onlyinherited
hasListeners bool
Whether any listeners are currently registered.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
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).
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
paint(PaintingContext context, Offset offset, Size size, PaintingContextCallback painter) → void
Paint the child via painter, applying any effects that would have been painted in SnapshotPainter.paintSnapshot.
paintSnapshot(PaintingContext context, Offset offset, Size size, Image image, Size sourceSize, double pixelRatio) → void
Called whenever the image that represents a SnapshotWidgets child should be painted.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
shouldRepaint(covariant SnapshotPainter oldPainter) bool
Called whenever a new instance of the snapshot widget delegate class is provided to the SnapshotWidget object, or any time that a new SnapshotPainter object is created with a new instance of the delegate class (which amounts to the same thing, because the latter is implemented in terms of the former).
toString() String
A string representation of this object.
inherited

Operators

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