SnapshotWidget class

A widget that can replace its child with a snapshotted version of the child.

A snapshot is a frozen texture-backed representation of all child pictures and layers stored as a ui.Image.

This widget is useful for performing short animations that would otherwise be expensive or that cannot rely on raster caching. For example, scale and skew animations are often expensive to perform on complex children, as are blurs. For a short animation, a widget that contains these expensive effects can be replaced with a snapshot of itself and manipulated instead.

For example, the Android Q ZoomPageTransitionsBuilder uses a snapshot widget for the forward and entering route to avoid the expensive scale animation. This also has the effect of briefly pausing any animations on the page.

Generally, this widget should not be used in places where users expect the child widget to continue animating or to be responsive, such as an unbounded animation.

Caveats:

  • The contents of platform views cannot be captured by a snapshot widget. If a platform view is encountered, then the snapshot widget will determine how to render its children based on the SnapshotMode. This defaults to SnapshotMode.normal which will throw an exception if a platform view is encountered.

  • The snapshotting functionality of this widget is not supported on the HTML backend of Flutter for the Web. Setting SnapshotController.allowSnapshotting to true may cause an error to be thrown. On the CanvasKit backend of Flutter, the performance of using this widget may regress performance due to the fact that both the UI and engine share a single thread.

Inheritance

Constructors

SnapshotWidget({Key? key, SnapshotMode mode = SnapshotMode.normal, SnapshotPainter painter = const _DefaultSnapshotPainter(), bool autoresize = false, required SnapshotController controller, required Widget? child})
Create a new SnapshotWidget.
const

Properties

autoresize bool
Whether or not changes in render object size should automatically re-create the snapshot.
final
child Widget?
The widget below this widget in the tree.
finalinherited
controller SnapshotController
The controller that determines when to display the children as a snapshot.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
mode SnapshotMode
Configuration that controls how the snapshot widget decides to paint its children.
final
painter SnapshotPainter
The painter used to paint the child snapshot or child widgets.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() SingleChildRenderObjectElement
RenderObjectWidgets always inflate to a RenderObjectElement subclass.
inherited
createRenderObject(BuildContext context) RenderObject
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
didUnmountRenderObject(covariant RenderObject renderObject) → void
A render object previously associated with this widget has been removed from the tree. The given RenderObject will be of the same type as returned by this object's createRenderObject.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited
updateRenderObject(BuildContext context, covariant RenderObject renderObject) → void
Copies the configuration described by this RenderObjectWidget to the given RenderObject, which will be of the same type as returned by this object's createRenderObject.
override

Operators

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