概述

#

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 後端已經需要類似的方法(compareButesupdateBytes)。

例如

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,其中建議合併 GoldenFileComparatorWebGoldenComparator

相關 PR

  • PR 161196,其中 WebGoldenComparator 被棄用,並且 flutter CLI 開始使用 goldenFileComparator