matchesGoldenFile function

AsyncMatcher matchesGoldenFile (dynamic key)

Asserts that a Finder, Future<ui.Image>, or ui.Image matches the golden image file identified by key.

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.

key may be either a Uri or a String representation of a URI.

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

Sample code

await expectLater(find.text('Save'), matchesGoldenFile('save.png'));
await expectLater(image, matchesGoldenFile('save.png'));
await expectLater(imageFuture, matchesGoldenFile('save.png'));

See also:

  • goldenFileComparator, which acts as the backend for this matcher.
  • matchesReferenceImage, which should be used instead if you want to verify that two different code paths create identical images.
  • flutter_test for a discussion of test configurations, whereby callers may swap out the backend for this matcher.

Implementation

AsyncMatcher matchesGoldenFile(dynamic key) {
  if (key is Uri) {
    return _MatchesGoldenFile(key);
  } else if (key is String) {
    return _MatchesGoldenFile.forStringPath(key);
  }
  throw ArgumentError('Unexpected type for golden file: ${key.runtimeType}');
}