Web-specific golden comparisons are no longer supported
Summary
#The flutter_test
package and flutter
tool will no longer use the
webGoldenComparator
top-level variable, and instead use the original
goldenFileComparator
top-level variable (like the non-web platforms).
For users of flutter_test
, these changes will be made automatically.
Background
#Originally, WebGoldenComparator
was added for
the HTML-backend of Flutter web, as it was not possible to create an encoded
PNG (byte buffer), and a new API was needed. As the HTML backend is being
deprecated and removed, this separate API is no longer necessary.
Migration guide
#For most users, no changes are required (other than migrating off the HTML
backend, which is not covered here), the flutter
tool will automatically
configure goldenFileComparator
and use it (when using a non-HTML web
backend).
For users that implement a custom WebGoldenComparator
, you will
migrate the implemenation to GoldenFileComparator
. Fortunately the
Canvas Kit and SkWasm backends already required similar methods (compareButes
and updateBytes
).
For example:
// Before
class MyWebGoldenComparator extends WebGoldenComparator {
@override
Future<bool> compare(double width, double height, Uri golden) {
// will be removed in the migration
}
@override
Future<bool> update(double width, double height, Uri golden) {
// will be removed in the migration
}
@override
Future<bool> compareBytes(Uint8List bytes, Uri golden) {
// will be renamed "compare"
}
@override
Future<bool> updateBytes(Uint8List bytes, Uri golden) {
// will be renamed "update" and the parameter orders swapped
}
}
// After
class MyGenericGoldenComparator extends GoldenFileComparator {
@override
Future<bool> compare(Uint8List bytes, Uri golden) {
// used to be "compareBytes"
}
@override
Future<bool> update(Uri golden, Uint8List bytes) {
// used to be "updateBytes"
}
}
Timeline
#Landed in version: 3.29.0-0.0.pre
In stable release: 3.29
References
#Relevant Issues:
- Issue 145954, where the HTML renderer was deprecated.
- Issue 160261, where it was proposed to consolidate
GoldenFileComparator
andWebGoldenComparator
.
Relevant PRs:
- PR 161196, where
WebGoldenComparator
was deprecated and theflutter
CLI started usinggoldenFileComparator
.
除非另有说明,本文档之所提及适用于 Flutter 的最新稳定版本,本页面最后更新时间: 2025-02-12。 查看文档源码 或者 为本页面内容提出建议。