3
3
// found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
- import 'dart:ui' as ui show ColorFilter, Image;
6
+ import 'dart:ui' as ui show Color, ColorFilter, Image;
7
7
8
8
import 'package:fake_async/fake_async.dart' ;
9
9
import 'package:flutter/foundation.dart' ;
@@ -14,6 +14,36 @@ import '../image_data.dart';
14
14
import '../painting/mocks_for_image_cache.dart' ;
15
15
import '../rendering/rendering_tester.dart' ;
16
16
17
+ /// Positive result if the colors would be mapped to the same argb8888 color.
18
+ class _ColorMatcher extends Matcher {
19
+ _ColorMatcher (this ._target);
20
+
21
+ final ui.Color _target;
22
+
23
+ @override
24
+ Description describe (Description description) {
25
+ return description.add ('matches "$_target "' );
26
+ }
27
+
28
+ @override
29
+ bool matches (dynamic item, Map <dynamic , dynamic > matchState) {
30
+ if (item is ui.Color ) {
31
+ return item.colorSpace == _target.colorSpace &&
32
+ (item.a - _target.a).abs () <= (1 / 255 ) &&
33
+ (item.r - _target.r).abs () <= (1 / 255 ) &&
34
+ (item.g - _target.g).abs () <= (1 / 255 ) &&
35
+ (item.b - _target.b).abs () <= (1 / 255 );
36
+ } else {
37
+ return false ;
38
+ }
39
+ }
40
+
41
+ }
42
+
43
+ Matcher _matchesColor (ui.Color color) {
44
+ return _ColorMatcher (color);
45
+ }
46
+
17
47
class TestCanvas implements Canvas {
18
48
final List <Invocation > invocations = < Invocation > [];
19
49
@@ -326,7 +356,7 @@ void main() {
326
356
expect (call.positionalArguments[3 ], isA <Paint >());
327
357
final Paint paint = call.positionalArguments[3 ] as Paint ;
328
358
expect (paint.colorFilter, colorFilter);
329
- expect (paint.color, const Color (0x7F000000 )); // 0.5 opacity
359
+ expect (paint.color, _matchesColor ( const Color (0x7F000000 ) )); // 0.5 opacity
330
360
expect (paint.filterQuality, FilterQuality .high);
331
361
expect (paint.isAntiAlias, true );
332
362
expect (paint.invertColors, isTrue);
0 commit comments