matchesReferenceImage function

AsyncMatcher matchesReferenceImage(
  1. Image image
)

Asserts that a Finder, Future<ui.Image>, or ui.Image matches a reference image identified by image.

For the case of a Finder, the Finder must match exactly one widget and the rendered image of the first RepaintBoundary ancestor of the widget is treated as the image for the widget.

This is an asynchronous matcher, meaning that callers should use expectLater when using this matcher and await the future returned by expectLater.

Sample code

testWidgets('matchesReferenceImage', (WidgetTester tester) async {
  final ui.Paint paint = ui.Paint()
    ..style = ui.PaintingStyle.stroke
    ..strokeWidth = 1.0;
  final ui.PictureRecorder recorder = ui.PictureRecorder();
  final ui.Canvas pictureCanvas = ui.Canvas(recorder);
  pictureCanvas.drawCircle(Offset.zero, 20.0, paint);
  final ui.Picture picture = recorder.endRecording();
  addTearDown(picture.dispose);
  ui.Image referenceImage = await picture.toImage(50, 50);
  addTearDown(referenceImage.dispose);

  await expectLater(find.text('Save'), matchesReferenceImage(referenceImage));
  await expectLater(image, matchesReferenceImage(referenceImage));
  await expectLater(imageFuture, matchesReferenceImage(referenceImage));
});

See also:

Implementation

AsyncMatcher matchesReferenceImage(ui.Image image) {
  return _MatchesReferenceImage(image);
}