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. - Adjust the size of the test viewport to the sheetSize (see the documentation of sheetSize for more information).
- Pump a frame that renders display, which shows all recorded frames in an animation sheet, and can be matched against the golden test.
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));
// Adjust view port size
tester.binding.setSurfaceSize(animationSheet.sheetSize());
// Display
final Widget display = await animationSheet.display();
await tester.pumpWidget(display);
// Compare against golden file
await expectLater(
find.byWidget(display),
matchesGoldenFile('inkwell.press.animation.png'),
);
}, skip: isBrowser); // Animation sheet does not support browser https://github.com/flutter/flutter/issues/56001
See also:
- GoldenFileComparator, which introduces Golden File Testing.
Constructors
- AnimationSheetBuilder({required Size frameSize})
- Starts a session of building an animation sheet. [...]
Properties
Methods
-
display(
{Key? key}) → Future< Widget> - Constructs a widget that renders the recorded frames in an animation sheet. [...]
-
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. [...]
-
toString(
) → String -
A string representation of this object. [...]
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator. [...]
inherited