AnimationSheetBuilder class Null safety

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.
  • 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.
testWidgets('Inkwell animation sheet', (WidgetTester tester) async {
  // Create instance
  final AnimationSheetBuilder animationSheet = AnimationSheetBuilder(frameSize: const Size(48, 24));

  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,
  ), const Duration(seconds: 1));

  await gesture.up();

  await tester.pumpFrames(animationSheet.record(
    target,
    recording: true,
  ), 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.
read-onlyinherited
runtimeType Type
A representation of the runtime type of the object.
read-onlyinherited

Methods

collate(int cellsPerRow) Future<Image>
Returns an result image by putting all frames together in a table.
display({Key? key}) Future<Widget>
Constructs a widget that renders the recorded frames in an animation sheet.
Deprecated('Use AnimationSheetBuilder.collate instead. ' 'This feature was deprecated after v2.3.0-13.0.pre.')">@Deprecated('Use AnimationSheetBuilder.collate instead. ' 'This feature was deprecated after v2.3.0-13.0.pre.')
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent 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.
sheetSize({double maxWidth = _kDefaultTestViewportWidth}) Size
Returns the smallest size that can contain all recorded frames.
Deprecated('The `sheetSize` is only useful for `display`, which should be migrated to `collate`. ' 'This feature was deprecated after v2.3.0-13.0.pre.')">@Deprecated('The `sheetSize` is only useful for `display`, which should be migrated to `collate`. ' 'This feature was deprecated after v2.3.0-13.0.pre.')
toString() String
A string representation of this object.
inherited

Operators

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