33// found in the LICENSE file.
44
55import 'dart:async' ;
6- import 'dart:ui' as ui show ColorFilter, Image;
6+ import 'dart:ui' as ui show Color, ColorFilter, Image;
77
88import 'package:fake_async/fake_async.dart' ;
99import 'package:flutter/foundation.dart' ;
@@ -14,6 +14,36 @@ import '../image_data.dart';
1414import '../painting/mocks_for_image_cache.dart' ;
1515import '../rendering/rendering_tester.dart' ;
1616
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+
1747class TestCanvas implements Canvas {
1848 final List <Invocation > invocations = < Invocation > [];
1949
@@ -326,7 +356,7 @@ void main() {
326356 expect (call.positionalArguments[3 ], isA <Paint >());
327357 final Paint paint = call.positionalArguments[3 ] as Paint ;
328358 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
330360 expect (paint.filterQuality, FilterQuality .high);
331361 expect (paint.isAntiAlias, true );
332362 expect (paint.invertColors, isTrue);
0 commit comments