gaaclarke
2024-09-05 16:11:03 -07:00
committed by GitHub
parent b0ed1cb4f4
commit 9e99675dbe

View File

@@ -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<dynamic, dynamic> 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<Invocation> invocations = <Invocation>[];
@@ -326,7 +356,7 @@ void main() {
expect(call.positionalArguments[3], isA<Paint>());
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);