diff --git a/packages/flutter/test/painting/decoration_test.dart b/packages/flutter/test/painting/decoration_test.dart index 677d9d9e3d..903e7be2f8 100644 --- a/packages/flutter/test/painting/decoration_test.dart +++ b/packages/flutter/test/painting/decoration_test.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'dart:async'; -import 'dart:ui' as ui show ColorFilter, Image; +import 'dart:ui' as ui show Color, ColorFilter, Image; import 'package:fake_async/fake_async.dart'; import 'package:flutter/foundation.dart'; @@ -14,6 +14,36 @@ import '../image_data.dart'; import '../painting/mocks_for_image_cache.dart'; import '../rendering/rendering_tester.dart'; +/// Positive result if the colors would be mapped to the same argb8888 color. +class _ColorMatcher extends Matcher { + _ColorMatcher(this._target); + + final ui.Color _target; + + @override + Description describe(Description description) { + return description.add('matches "$_target"'); + } + + @override + bool matches(dynamic item, Map matchState) { + if (item is ui.Color) { + return item.colorSpace == _target.colorSpace && + (item.a - _target.a).abs() <= (1 / 255) && + (item.r - _target.r).abs() <= (1 / 255) && + (item.g - _target.g).abs() <= (1 / 255) && + (item.b - _target.b).abs() <= (1 / 255); + } else { + return false; + } + } + +} + +Matcher _matchesColor(ui.Color color) { + return _ColorMatcher(color); +} + class TestCanvas implements Canvas { final List invocations = []; @@ -326,7 +356,7 @@ void main() { expect(call.positionalArguments[3], isA()); final Paint paint = call.positionalArguments[3] as Paint; expect(paint.colorFilter, colorFilter); - expect(paint.color, const Color(0x7F000000)); // 0.5 opacity + expect(paint.color, _matchesColor(const Color(0x7F000000))); // 0.5 opacity expect(paint.filterQuality, FilterQuality.high); expect(paint.isAntiAlias, true); expect(paint.invertColors, isTrue);