不再支持特定于 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
参考资料
#相关问题
- Issue 145954,其中 HTML 渲染器被弃用。
- Issue 160261,其中建议合并
GoldenFileComparator和WebGoldenComparator。
相关 PR
- PR 161196,其中
WebGoldenComparator被弃用,并且flutterCLI 开始使用goldenFileComparator。