@@ -44,7 +44,8 @@ bool _isAlmost(double x, double y, double epsilon) {
4444List <double > _deepRed = < double > [1.0931 , - 0.2268 , - 0.1501 ];
4545
4646bool _findRGBAF16Color (
47- Uint8List bytes, int width, int height, List <double > color) {
47+ Uint8List bytes, int width, int height, List <double > color,
48+ {required double epsilon}) {
4849 final ByteData byteData = ByteData .sublistView (bytes);
4950 expect (bytes.lengthInBytes, width * height * 8 );
5051 expect (bytes.lengthInBytes, byteData.lengthInBytes);
@@ -54,17 +55,18 @@ bool _findRGBAF16Color(
5455 final double blue = _decodeHalf ((pixel >> 32 ) & 0xffff );
5556 final double green = _decodeHalf ((pixel >> 16 ) & 0xffff );
5657 final double red = _decodeHalf ((pixel >> 0 ) & 0xffff );
57- if (_isAlmost (red, color[0 ], 0.01 ) &&
58- _isAlmost (green, color[1 ], 0.01 ) &&
59- _isAlmost (blue, color[2 ], 0.01 )) {
58+ if (_isAlmost (red, color[0 ], epsilon ) &&
59+ _isAlmost (green, color[1 ], epsilon ) &&
60+ _isAlmost (blue, color[2 ], epsilon )) {
6061 foundDeepRed = true ;
6162 }
6263 }
6364 return foundDeepRed;
6465}
6566
6667bool _findBGRA10Color (
67- Uint8List bytes, int width, int height, List <double > color) {
68+ Uint8List bytes, int width, int height, List <double > color,
69+ {required double epsilon}) {
6870 final ByteData byteData = ByteData .sublistView (bytes);
6971 expect (bytes.lengthInBytes, width * height * 8 );
7072 expect (bytes.lengthInBytes, byteData.lengthInBytes);
@@ -74,17 +76,17 @@ bool _findBGRA10Color(
7476 final double blue = _decodeBGR10 ((pixel >> 6 ) & 0x3ff );
7577 final double green = _decodeBGR10 ((pixel >> 22 ) & 0x3ff );
7678 final double red = _decodeBGR10 ((pixel >> 38 ) & 0x3ff );
77- if (_isAlmost (red, color[0 ], 0.01 ) &&
78- _isAlmost (green, color[1 ], 0.01 ) &&
79- _isAlmost (blue, color[2 ], 0.01 )) {
79+ if (_isAlmost (red, color[0 ], epsilon ) &&
80+ _isAlmost (green, color[1 ], epsilon ) &&
81+ _isAlmost (blue, color[2 ], epsilon )) {
8082 foundDeepRed = true ;
8183 }
8284 }
8385 return foundDeepRed;
8486}
8587
86- bool _findBGR10Color (
87- Uint8List bytes, int width, int height, List < double > color ) {
88+ bool _findBGR10Color (Uint8List bytes, int width, int height, List < double > color,
89+ { required double epsilon} ) {
8890 final ByteData byteData = ByteData .sublistView (bytes);
8991 expect (bytes.lengthInBytes, width * height * 4 );
9092 expect (bytes.lengthInBytes, byteData.lengthInBytes);
@@ -94,23 +96,27 @@ bool _findBGR10Color(
9496 final double blue = _decodeBGR10 (pixel & 0x3ff );
9597 final double green = _decodeBGR10 ((pixel >> 10 ) & 0x3ff );
9698 final double red = _decodeBGR10 ((pixel >> 20 ) & 0x3ff );
97- if (_isAlmost (red, color[0 ], 0.01 ) &&
98- _isAlmost (green, color[1 ], 0.01 ) &&
99- _isAlmost (blue, color[2 ], 0.01 )) {
99+ if (_isAlmost (red, color[0 ], epsilon ) &&
100+ _isAlmost (green, color[1 ], epsilon ) &&
101+ _isAlmost (blue, color[2 ], epsilon )) {
100102 foundDeepRed = true ;
101103 }
102104 }
103105 return foundDeepRed;
104106}
105107
106- bool _findColor (List <dynamic > result, List <double > color) {
108+ bool _findColor (List <dynamic > result, List <double > color,
109+ {double epsilon = 0.01 }) {
107110 expect (result, isNotNull);
108111 expect (result.length, 4 );
109112 final [int width, int height, String format, Uint8List bytes] = result;
110113 return switch (format) {
111- 'MTLPixelFormatBGR10_XR' => _findBGR10Color (bytes, width, height, color),
112- 'MTLPixelFormatBGRA10_XR' => _findBGRA10Color (bytes, width, height, color),
113- 'MTLPixelFormatRGBA16Float' => _findRGBAF16Color (bytes, width, height, color),
114+ 'MTLPixelFormatBGR10_XR' =>
115+ _findBGR10Color (bytes, width, height, color, epsilon: epsilon),
116+ 'MTLPixelFormatBGRA10_XR' =>
117+ _findBGRA10Color (bytes, width, height, color, epsilon: epsilon),
118+ 'MTLPixelFormatRGBA16Float' =>
119+ _findRGBAF16Color (bytes, width, height, color, epsilon: epsilon),
114120 _ => fail ('Unsupported pixel format: $format ' ),
115121 };
116122}
@@ -157,7 +163,8 @@ void main() {
157163 expect (_findColor (result, _deepRed), isTrue);
158164 expect (_findColor (result, < double > [0.0 , 1.0 , 0.0 ]), isTrue);
159165 });
160- testWidgets ('draw image with wide gamut works' , (WidgetTester tester) async {
166+ testWidgets ('draw image with wide gamut works' ,
167+ (WidgetTester tester) async {
161168 app.run (app.Setup .drawnImage);
162169 await tester.pumpAndSettle (const Duration (seconds: 2 ));
163170
@@ -166,7 +173,8 @@ void main() {
166173 await channel.invokeMethod ('test' ) as List <Object ?>;
167174 expect (_findColor (result, < double > [0.0 , 1.0 , 0.0 ]), isTrue);
168175 });
169- testWidgets ('draw container with wide gamut works' , (WidgetTester tester) async {
176+ testWidgets ('draw container with wide gamut works' ,
177+ (WidgetTester tester) async {
170178 app.run (app.Setup .container);
171179 await tester.pumpAndSettle (const Duration (seconds: 2 ));
172180
@@ -175,5 +183,49 @@ void main() {
175183 await channel.invokeMethod ('test' ) as List <Object ?>;
176184 expect (_findColor (result, _deepRed), isTrue);
177185 });
186+
187+ testWidgets ('draw wide gamut linear gradient works' ,
188+ (WidgetTester tester) async {
189+ app.run (app.Setup .linearGradient);
190+ await tester.pumpAndSettle (const Duration (seconds: 2 ));
191+
192+ const MethodChannel channel = MethodChannel ('flutter/screenshot' );
193+ final List <Object ?> result =
194+ await channel.invokeMethod ('test' ) as List <Object ?>;
195+ expect (_findColor (result, _deepRed), isTrue);
196+ });
197+
198+ testWidgets ('draw wide gamut radial gradient works' ,
199+ (WidgetTester tester) async {
200+ app.run (app.Setup .radialGradient);
201+ await tester.pumpAndSettle (const Duration (seconds: 2 ));
202+
203+ const MethodChannel channel = MethodChannel ('flutter/screenshot' );
204+ final List <Object ?> result =
205+ await channel.invokeMethod ('test' ) as List <Object ?>;
206+ expect (_findColor (result, _deepRed, epsilon: 0.05 ), isTrue);
207+ });
208+
209+ testWidgets ('draw wide gamut conical gradient works' ,
210+ (WidgetTester tester) async {
211+ app.run (app.Setup .conicalGradient);
212+ await tester.pumpAndSettle (const Duration (seconds: 2 ));
213+
214+ const MethodChannel channel = MethodChannel ('flutter/screenshot' );
215+ final List <Object ?> result =
216+ await channel.invokeMethod ('test' ) as List <Object ?>;
217+ expect (_findColor (result, _deepRed, epsilon: 0.05 ), isTrue);
218+ });
219+
220+ testWidgets ('draw wide gamut sweep gradient works' ,
221+ (WidgetTester tester) async {
222+ app.run (app.Setup .sweepGradient);
223+ await tester.pumpAndSettle (const Duration (seconds: 2 ));
224+
225+ const MethodChannel channel = MethodChannel ('flutter/screenshot' );
226+ final List <Object ?> result =
227+ await channel.invokeMethod ('test' ) as List <Object ?>;
228+ expect (_findColor (result, _deepRed), isTrue);
229+ });
178230 });
179231}
0 commit comments