@@ -33,17 +33,21 @@ class _FakeAssetBundle extends AssetBundle {
3333void main () {
3434 group ('Scene JSON round trip' , () {
3535 test ('round-trips width/height/background/layers' , () {
36- final scene = Scene (
37- width: 200 ,
38- height: 100 ,
39- background: MemoryImageSource (Uint8List .fromList ([1 , 2 , 3 ])),
40- )..addAll ([
41- Layers .rectangle (size: const Size (50 , 50 ), color: const Color (0xFFFF0000 )),
42- Layers .text (text: 'hello' , fontWeight: FontWeight .w600),
43- Layers .group (
44- children: [Layers .rectangle (size: const Size (10 , 10 ))],
45- ),
46- ]);
36+ final scene =
37+ Scene (
38+ width: 200 ,
39+ height: 100 ,
40+ background: MemoryImageSource (Uint8List .fromList ([1 , 2 , 3 ])),
41+ )..addAll ([
42+ Layers .rectangle (
43+ size: const Size (50 , 50 ),
44+ color: const Color (0xFFFF0000 ),
45+ ),
46+ Layers .text (text: 'hello' , fontWeight: FontWeight .w600),
47+ Layers .group (
48+ children: [Layers .rectangle (size: const Size (10 , 10 ))],
49+ ),
50+ ]);
4751
4852 final decoded = Scene .fromJson (
4953 jsonDecode (jsonEncode (scene.toJson ())) as Map <String , Object ?>,
@@ -60,60 +64,66 @@ void main() {
6064 });
6165
6266 group ('resolveSceneAssetSources' , () {
63- test ('returns the same Scene instance when no AssetImageSource exists' , () async {
64- final scene = Scene (width: 10 , height: 10 )
65- ..add (
66- Layers .image (
67- source: MemoryImageSource (Uint8List .fromList ([1 ])),
68- size: const Size (10 , 10 ),
69- ),
67+ test (
68+ 'returns the same Scene instance when no AssetImageSource exists' ,
69+ () async {
70+ final scene = Scene (width: 10 , height: 10 )
71+ ..add (
72+ Layers .image (
73+ source: MemoryImageSource (Uint8List .fromList ([1 ])),
74+ size: const Size (10 , 10 ),
75+ ),
76+ );
77+ final bundle = _FakeAssetBundle (Uint8List .fromList ([9 , 9 , 9 ]));
78+
79+ final resolved = await resolveSceneAssetSources (scene, bundle);
80+
81+ expect (identical (resolved, scene), isTrue);
82+ expect (bundle.loadedKeys, isEmpty);
83+ },
84+ );
85+
86+ test (
87+ 'resolves an AssetImageSource background into MemoryImageSource' ,
88+ () async {
89+ final scene = Scene (
90+ width: 10 ,
91+ height: 10 ,
92+ background: AssetImageSource ('images/bg.png' ),
7093 );
71- final bundle = _FakeAssetBundle (Uint8List .fromList ([9 , 9 , 9 ]));
72-
73- final resolved = await resolveSceneAssetSources (scene, bundle);
74-
75- expect (identical (resolved, scene), isTrue);
76- expect (bundle.loadedKeys, isEmpty);
77- });
78-
79- test ('resolves an AssetImageSource background into MemoryImageSource' , () async {
80- final scene = Scene (
81- width: 10 ,
82- height: 10 ,
83- background: AssetImageSource ('images/bg.png' ),
84- );
85- final bundle = _FakeAssetBundle (Uint8List .fromList ([1 , 2 , 3 ]));
86-
87- final resolved = await resolveSceneAssetSources (scene, bundle);
88-
89- expect (resolved.background, isA <MemoryImageSource >());
90- expect (
91- (resolved.background as MemoryImageSource ).bytes,
92- [1 , 2 , 3 ],
93- );
94- expect (bundle.loadedKeys, ['images/bg.png' ]);
95- });
96-
97- test ('resolves an AssetImageSource on an ImageLayer, preserving fields' , () async {
98- final scene = Scene (width: 10 , height: 10 )
99- ..add (
100- Layers .image (
101- source: AssetImageSource ('images/logo.png' ),
102- size: const Size (10 , 10 ),
103- fit: BoxFit .cover,
104- position: const Offset (1 , 2 ),
105- ),
106- );
107- final bundle = _FakeAssetBundle (Uint8List .fromList ([4 , 5 , 6 ]));
108-
109- final resolved = await resolveSceneAssetSources (scene, bundle);
110-
111- final layer = resolved.layers.single as ImageLayer ;
112- expect (layer.source, isA <MemoryImageSource >());
113- expect (layer.fit, ImageFit .cover);
114- expect (layer.transform.position, const Point2D (1 , 2 ));
115- expect (layer.size, const Size2D (10 , 10 ));
116- });
94+ final bundle = _FakeAssetBundle (Uint8List .fromList ([1 , 2 , 3 ]));
95+
96+ final resolved = await resolveSceneAssetSources (scene, bundle);
97+
98+ expect (resolved.background, isA <MemoryImageSource >());
99+ expect ((resolved.background as MemoryImageSource ).bytes, [1 , 2 , 3 ]);
100+ expect (bundle.loadedKeys, ['images/bg.png' ]);
101+ },
102+ );
103+
104+ test (
105+ 'resolves an AssetImageSource on an ImageLayer, preserving fields' ,
106+ () async {
107+ final scene = Scene (width: 10 , height: 10 )
108+ ..add (
109+ Layers .image (
110+ source: AssetImageSource ('images/logo.png' ),
111+ size: const Size (10 , 10 ),
112+ fit: BoxFit .cover,
113+ position: const Offset (1 , 2 ),
114+ ),
115+ );
116+ final bundle = _FakeAssetBundle (Uint8List .fromList ([4 , 5 , 6 ]));
117+
118+ final resolved = await resolveSceneAssetSources (scene, bundle);
119+
120+ final layer = resolved.layers.single as ImageLayer ;
121+ expect (layer.source, isA <MemoryImageSource >());
122+ expect (layer.fit, ImageFit .cover);
123+ expect (layer.transform.position, const Point2D (1 , 2 ));
124+ expect (layer.size, const Size2D (10 , 10 ));
125+ },
126+ );
117127
118128 test ('recurses into Group children' , () async {
119129 final scene = Scene (width: 10 , height: 10 )
0 commit comments