不再支持 Web 专属的黄金比对
概述
#flutter_test
包和 flutter
工具将不再使用 webGoldenComparator
顶层变量,转而使用原始的 goldenFileComparator
顶层变量(与非 Web 平台一致)。
对于 flutter_test
的用户而言,这些更改将自动完成。
背景
#最初,WebGoldenComparator
是为 Flutter Web 的 HTML 后端添加的,因为当时无法创建编码的 PNG(字节缓冲区),所以需要一个新的 API。由于 HTML 后端正在被弃用和移除,这个独立的 API 不再需要。
迁移指南
#对于大多数用户来说,无需进行任何更改(除了从 HTML 后端迁移出来,这部分不在此处讨论),flutter
工具将自动配置 goldenFileComparator
并使用它(在使用非 HTML 的 Web 后端时)。
对于实现自定义 WebGoldenComparator
的用户,您需要将实现迁移到 GoldenFileComparator
。幸运的是,Canvas Kit 和 SkWasm 后端已经需要类似的方法(compareButes
和 updateBytes
)。
例如
dart
// 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"
}
}
时间线
#已发布版本:3.29.0-0.0.pre
稳定版发布于: 3.29
参考资料
#相关问题
相关 PR
- 拉取请求 161196,其中
WebGoldenComparator
被弃用,并且flutter
CLI 开始使用goldenFileComparator
。