1
1
import 'dart:convert' ;
2
2
import 'dart:io' ;
3
- import 'dart:typed_data' ;
4
3
import 'dart:ui' as ui;
5
4
6
5
import 'package:flutter/rendering.dart' ;
@@ -23,10 +22,13 @@ GoldenCollection extractGoldenCollectionFromSceneFile(File file) {
23
22
final scenePngBytes = file.readAsBytesSync ();
24
23
25
24
// Extract scene metadata from PNG.
26
- final sceneMetadata = _extractGoldenSceneMetadataFromBytes (scenePngBytes);
27
- if (sceneMetadata == null ) {
25
+ final pngText = scenePngBytes.readTextMetadata ();
26
+ final sceneJsonText = pngText["flutter_test_goldens" ];
27
+ if (sceneJsonText == null ) {
28
28
throw Exception ("Golden image is missing scene metadata: ${file .path }" );
29
29
}
30
+ final sceneJson = JsonDecoder ().convert (sceneJsonText);
31
+ final sceneMetadata = GoldenSceneMetadata .fromJson (sceneJson);
30
32
31
33
// Decode PNG data to an image.
32
34
final sceneImage = decodePng (scenePngBytes);
@@ -82,31 +84,6 @@ Future<GoldenCollection> extractGoldenCollectionFromSceneWidgetTree(
82
84
return _extractCollectionFromScene (sceneMetadata, treeImage);
83
85
}
84
86
85
- /// Extracts then golden scene metadata within the given image [file] .
86
- GoldenSceneMetadata extractGoldenSceneMetadataFromFile (File file) {
87
- // Read the scene PNG data into memory.
88
- final scenePngBytes = file.readAsBytesSync ();
89
-
90
- // Extract scene metadata from PNG.
91
- final sceneMetadata = _extractGoldenSceneMetadataFromBytes (scenePngBytes);
92
- if (sceneMetadata == null ) {
93
- throw Exception ("Golden image is missing scene metadata: ${file .path }" );
94
- }
95
-
96
- return sceneMetadata;
97
- }
98
-
99
- GoldenSceneMetadata ? _extractGoldenSceneMetadataFromBytes (Uint8List pngBytes) {
100
- // Extract scene metadata from PNG.
101
- final pngText = pngBytes.readTextMetadata ();
102
- final sceneJsonText = pngText["flutter_test_goldens" ];
103
- if (sceneJsonText == null ) {
104
- return null ;
105
- }
106
- final sceneJson = JsonDecoder ().convert (sceneJsonText);
107
- return GoldenSceneMetadata .fromJson (sceneJson);
108
- }
109
-
110
87
GoldenCollection _extractCollectionFromScene (GoldenSceneMetadata sceneMetadata, Image sceneImage) {
111
88
// Cut each golden image out of the scene.
112
89
final goldenImages = < String , GoldenImage > {};
0 commit comments