Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4880770

Browse files
committed
moved equality and toString
1 parent 674e37a commit 4880770

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

lib/ui/painting.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,19 @@ class Color {
419419
return false;
420420
}
421421
return other is Color &&
422-
other.value == value &&
422+
other.a == a &&
423+
other.r == r &&
424+
other.g == g &&
425+
other.b == b &&
423426
other.colorSpace == colorSpace;
424427
}
425428

426429
@override
427-
int get hashCode => Object.hash(value, colorSpace);
430+
int get hashCode => Object.hash(a, r, g, b, colorSpace);
428431

429-
// TODO(gaaclarke): Make toString() print out float values.
430432
@override
431-
String toString() => 'Color(0x${value.toRadixString(16).padLeft(8, '0')})';
433+
String toString() =>
434+
'Color(alpha: ${a.toStringAsFixed(4)}, red: ${r.toStringAsFixed(4)}, green: ${g.toStringAsFixed(4)}, blue: ${b.toStringAsFixed(4)}, colorSpace: $colorSpace)';
432435
}
433436

434437
/// Algorithms to use when painting on the canvas.

testing/dart/color_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
const Color c = Color(0x00000000);
4141
final Paint p = Paint();
4242
p.color = c;
43-
expect(c.toString(), equals('Color(0x00000000)'));
43+
expect(c, equals(const Color(0x00000000)));
4444
});
4545

4646
test('color created with out of bounds value', () {
@@ -161,15 +161,15 @@ void main() {
161161
);
162162
expect(
163163
Color.alphaBlend(const Color(0x80808080), const Color(0xFFFFFFFF)),
164-
const Color(0xFFBFBFBF),
164+
colorMatches(const Color(0xFFBFBFBF)),
165165
);
166166
expect(
167167
Color.alphaBlend(const Color(0x80808080), const Color(0xFF000000)),
168-
const Color(0xFF404040),
168+
colorMatches(const Color(0xFF404040)),
169169
);
170170
expect(
171171
Color.alphaBlend(const Color(0x01020304), const Color(0xFF000000)),
172-
const Color(0xFF000000),
172+
colorMatches(const Color(0xFF000000)),
173173
);
174174
expect(
175175
Color.alphaBlend(const Color(0x11223344), const Color(0xFF000000)),

0 commit comments

Comments
 (0)