diff --git a/engine/src/flutter/lib/ui/painting.dart b/engine/src/flutter/lib/ui/painting.dart index e69a712a6d..e2c69dadb3 100644 --- a/engine/src/flutter/lib/ui/painting.dart +++ b/engine/src/flutter/lib/ui/painting.dart @@ -170,7 +170,9 @@ class Color { @override bool operator ==(dynamic other) { - if (other is! Color) + if (identical(this, other)) + return true; + if (other.runtimeType != runtimeType) return false; final Color typedOther = other; return value == typedOther.value; diff --git a/engine/src/flutter/testing/dart/color_test.dart b/engine/src/flutter/testing/dart/color_test.dart index 2b231f94ba..5721c9a505 100644 --- a/engine/src/flutter/testing/dart/color_test.dart +++ b/engine/src/flutter/testing/dart/color_test.dart @@ -6,6 +6,10 @@ import 'dart:ui'; import 'package:test/test.dart'; +class NotAColor extends Color { + const NotAColor(int value) : super(value); +} + void main() { test("color accessors should work", () { Color foo = const Color(0x12345678); @@ -41,4 +45,14 @@ void main() { expect(e != null, equals(true)); } }); + + test("two colors are only == if they have the same runtime type", () { + expect(const Color(123), equals(const Color(123))); + expect(const Color(123), equals(new Color(123))); + expect(const Color(123), isNot(equals(const Color(321)))); + expect(const Color(123), isNot(equals(const NotAColor(123)))); + expect(const NotAColor(123), isNot(equals(const Color(123)))); + expect(const NotAColor(123), equals(const NotAColor(123))); + }); + }