RasterWidgetDelegate class Null safety

A delegate used to draw the image representing the rasterized child.

The delegate can call notifyListeners to have the raster widget re-paint (re-using the same raster). This allows animations to be connected to the raster and performed without re-rasterization 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 RasterWidget 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.
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

RasterWidgetDelegate()

Properties

hashCode int
The hash code for this object.
read-onlyinherited
hasListeners bool
Whether any listeners are currently registered.
protected">@protectedread-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).
mustCallSuper">@mustCallSuperinherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
protected">@protectedvisibleForTesting">@visibleForTestinginherited
paint(PaintingContext context, Offset offset, Size size, Image image, double pixelRatio) → void
Called whenever the image that represents a RasterWidgets 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 RasterWidgetDelegate oldDelegate) bool
Called whenever a new instance of the raster widget delegate class is provided to the RenderRasterWidget object, or any time that a new RasterWidgetDelegate 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