AnimatedSampler class

A widget that allows access to a snapshot of the child widgets for painting with a sampler applied to a FragmentProgram.

When enabled is true, the child widgets will be painted into a texture exposed as a ui.Image. This can then be passed to a FragmentShader instance via FragmentShader.setSampler.

If enabled is false, then the child widgets are painted as normal.

Caveats:

  • Platform views cannot be captured in a texture. If any are present they will be excluded from the texture. Texture-based platform views are OK.

Example:

Providing an image to a fragment shader using FragmentShader.setImageSampler.

Widget build(BuildContext context) {
  return AnimatedSampler(
    (ui.Image image, Size size, Canvas canvas) {
      shader
        ..setFloat(0, size.width)
        ..setFloat(1, size.height)
        ..setImageSampler(0, image);
      canvas.drawRect(Offset.zero & size, Paint()..shader = shader);
    },
    child: widget.child,
  );
}

See also:

  • SnapshotWidget, which provides a similar API for the purpose of caching during expensive animations.
Inheritance

Constructors

AnimatedSampler(AnimatedSamplerBuilder builder, {required Widget child, Key? key, bool enabled = true})
Create a new AnimatedSampler.
const

Properties

builder AnimatedSamplerBuilder
A callback used by this widget to provide the children captured in a texture.
final
child Widget
The child widget.
final
enabled bool
Whether the children should be captured in a texture or displayed as normal.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

build(BuildContext context) Widget
Describes the part of the user interface represented by this widget.
override
createElement() StatelessElement
Creates a StatelessElement to manage this widget's location in the tree.
inherited
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
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

Operators

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