Skip to content

Commit ea2fbe5

Browse files
committed
Extract image data to bytes
So the test can run with Flutter for Web
1 parent a35584d commit ea2fbe5

2 files changed

Lines changed: 50 additions & 23 deletions

File tree

‎packages/flutter/test/painting/image_data.dart‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,52 @@ const List<int> kAnimatedGif = <int> [
2323
0xf9, 0x04, 0x00, 0x0a, 0x00, 0xff, 0x00, 0x2c, 0x00, 0x00, 0x00, 0x00, 0x01,
2424
0x00, 0x01, 0x00, 0x00, 0x02, 0x02, 0x44, 0x01, 0x00, 0x3b,
2525
];
26+
27+
// A PNG with 100x100 blue pixels.
28+
//
29+
// Constructed by the following code:
30+
// ```dart
31+
// Future<void> someTest(WidgetTester tester) async {
32+
// Uint8List bytes;
33+
// await tester.runAsync(() async {
34+
// const int imageWidth = 100;
35+
// const int imageHeight = 100;
36+
// final Uint8List pixels = Uint8List.fromList(List<int>.generate(
37+
// imageWidth * imageHeight * 4,
38+
// (int i) => i % 4 < 2 ? 0x00 : 0xFF, // opaque blue
39+
// ));
40+
// final Completer<void> completer = Completer<void>();
41+
// ui.decodeImageFromPixels(
42+
// pixels, imageWidth, imageHeight, ui.PixelFormat.rgba8888,
43+
// (ui.Image image) async {
44+
// final ByteData byteData = await image.toByteData(
45+
// format: ui.ImageByteFormat.png);
46+
// bytes = byteData.buffer.asUint8List();
47+
// completer.complete();
48+
// },
49+
// );
50+
// await completer.future;
51+
// });
52+
// print(bytes);
53+
// }
54+
// ```
55+
const List<int> kBlueRectPng = <int> [
56+
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 100, 0,
57+
0, 0, 100, 8, 6, 0, 0, 0, 112, 226, 149, 84, 0, 0, 0, 4, 115, 66, 73, 84, 8,
58+
8, 8, 8, 124, 8, 100, 136, 0, 0, 1, 0, 73, 68, 65, 84, 120, 156, 237, 209, 65,
59+
13, 0, 32, 16, 192, 176, 3, 255, 158, 225, 141, 2, 246, 104, 21, 44, 217, 154,
60+
57, 103, 200, 216, 191, 3, 120, 25, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
61+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
62+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
63+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
64+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
65+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
66+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
67+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
68+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
69+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
70+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
71+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 140, 33, 49, 134, 196, 24, 18,
72+
99, 72, 140, 33, 49, 134, 196, 24, 18, 99, 72, 204, 5, 234, 78, 2, 198, 180,
73+
170, 48, 200, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
74+
];

‎packages/flutter/test/widgets/image_test.dart‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,34 +1623,12 @@ void main() {
16231623
});
16241624

16251625
Future<void> _testRotatedImage(WidgetTester tester, bool isAntiAlias) async {
1626-
// Construct a PNG of 100x100 blue pixels as Image widget doesn't support raw RGBA.
1627-
Uint8List bytes;
1628-
await tester.runAsync(() async {
1629-
const int imageWidth = 100;
1630-
const int imageHeight = 100;
1631-
final Uint8List pixels = Uint8List.fromList(List<int>.generate(
1632-
imageWidth * imageHeight * 4,
1633-
(int i) => i % 4 < 2 ? 0x00 : 0xFF, // opaque blue
1634-
));
1635-
final Completer<void> completer = Completer<void>();
1636-
ui.decodeImageFromPixels(
1637-
pixels, imageWidth, imageHeight, ui.PixelFormat.rgba8888,
1638-
(ui.Image image) async {
1639-
final ByteData byteData = await image.toByteData(
1640-
format: ui.ImageByteFormat.png);
1641-
bytes = byteData.buffer.asUint8List();
1642-
completer.complete();
1643-
},
1644-
);
1645-
await completer.future;
1646-
});
1647-
16481626
final Key key = UniqueKey();
16491627
await tester.pumpWidget(RepaintBoundary(
16501628
key: key,
16511629
child: Transform.rotate(
16521630
angle: math.pi / 180,
1653-
child: Image.memory(bytes, isAntiAlias: isAntiAlias),
1631+
child: Image.memory(Uint8List.fromList(kBlueRectPng), isAntiAlias: isAntiAlias),
16541632
),
16551633
));
16561634

0 commit comments

Comments
 (0)