LocalFileComparator class Null safety

The default GoldenFileComparator implementation for flutter test.

The term golden file refers to a master image that is considered the true rendering of a given widget, state, application, or other visual representation you have chosen to capture. This comparator loads golden files from the local file system, treating the golden key as a relative path from the test file's directory.

This comparator performs a pixel-for-pixel comparison of the decoded PNGs, returning true only if there's an exact match. In cases where the captured test image does not match the golden file, this comparator will provide output to illustrate the difference, described in further detail below.

When using flutter test --update-goldens, LocalFileComparator updates the golden files on disk to match the rendering.

Local Output from Golden File Testing

The LocalFileComparator will output test feedback when a golden file test fails. This output takes the form of differential images contained within a failures directory that will be generated in the same location specified by the golden key. The differential images include the master and test images that were compared, as well as an isolated diff of detected pixels, and a masked diff that overlays these detected pixels over the master image.

The following images are examples of a test failure output:

File NameImage Output
testName_masterImage.pngA golden master image
testName_testImage.pngTest image
testName_isolatedDiff.pngAn isolated pixel difference.
testName_maskedDiff.pngA masked pixel difference

See also:

Mixed in types


LocalFileComparator(Uri testFile, {Style? pathStyle})
Creates a new LocalFileComparator for the specified testFile. [...]


basedir Uri
The directory in which the test was loaded. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


compare(Uint8List imageBytes, Uri golden) Future<bool>
Compares the pixels of decoded png imageBytes against the golden file identified by golden. [...]
generateFailureOutput(ComparisonResult result, Uri golden, Uri basedir, {String key = ''}) Future<String>
Writes out diffs from the ComparisonResult of a golden file test. [...]
getFailureFile(String failure, Uri golden, Uri basedir) File
Returns the appropriate file for a given diff from a ComparisonResult.
getGoldenBytes(Uri golden) Future<List<int>>
Returns the bytes of the given golden file. [...]
getTestUri(Uri key, int? version) Uri
Returns a new golden file Uri to incorporate any version number with the key. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
toString() String
A string representation of this object. [...]
update(Uri golden, Uint8List imageBytes) Future<void>
Updates the golden file identified by golden with imageBytes. [...]


operator ==(Object other) bool
The equality operator. [...]