AnimationSheetBuilder class

Records the frames of an animating widget, and later displays the frames as a grid in an animation sheet.

This class does not support Web, because the animation sheet utilizes taking screenshots, which is unsupported on the Web. Tests that use this class must be noted with skip: isBrowser. (https://github.com/flutter/flutter/issues/56001)

Using this class includes the following steps:

  • Create an instance of this class.
  • Register dispose to the test's tear down callbacks.
  • Pump frames that render the target widget wrapped in record. Every frame that has recording being true will be recorded.
  • Acquire the output image with collate and compare against the golden file.

The following example shows how to record an animation sheet of an InkWell being pressed then released.
link
testWidgets('Inkwell animation sheet', (WidgetTester tester) async {
  // Create instance
  final AnimationSheetBuilder animationSheet = AnimationSheetBuilder(frameSize: const Size(48, 24));
  addTearDown(animationSheet.dispose);

  final Widget target = Material(
    child: Directionality(
      textDirection: TextDirection.ltr,
      child: InkWell(
        splashColor: Colors.blue,
        onTap: () {},
      ),
    ),
  );

  // Optional: setup before recording (`recording` is false)
  await tester.pumpWidget(animationSheet.record(
    target,
    recording: false,
  ));

  final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(InkWell)));

  // Start recording (`recording` is true)
  await tester.pumpFrames(animationSheet.record(
    target,
    recording: true, // ignore: avoid_redundant_argument_values
  ), const Duration(seconds: 1));

  await gesture.up();

  await tester.pumpFrames(animationSheet.record(
    target,
    recording: true, // ignore: avoid_redundant_argument_values
  ), const Duration(seconds: 1));

  // Compare against golden file
  await expectLater(
    animationSheet.collate(800),
    matchesGoldenFile('inkwell.press.animation.png'),
  );
}, skip: isBrowser); // Animation sheet does not support browser https://github.com/flutter/flutter/issues/56001

See also:

Constructors

AnimationSheetBuilder({required Size frameSize, bool allLayers = false})
Starts a session of building an animation sheet.

Properties

allLayers bool
Whether the captured image comes from the entire tree, or only the subtree of record.
final
frameSize Size
The size of the child to be recorded.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

collate(int cellsPerRow) Future<Image>
Returns an result image by putting all frames together in a table.
dispose() Future<void>
Dispose all recorded frames and result images.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
record(Widget child, {Key? key, bool recording = true}) Widget
Returns a widget that renders a widget in a box that can be recorded.
toString() String
A string representation of this object.
inherited

Operators

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