matchesReferenceImage function

AsyncMatcher matchesReferenceImage (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

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();
ui.Image referenceImage = picture.toImage(50, 50);

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);
}