From 4680ff3a795e37cc317500655370b795dc493044 Mon Sep 17 00:00:00 2001 From: Ayaan Khan Date: Fri, 7 Aug 2020 04:36:10 +0530 Subject: [PATCH] fix: MaterialColor Swatch Map comparison (#61974) --- packages/flutter/lib/src/painting/colors.dart | 2 +- .../flutter/test/painting/colors_test.dart | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/painting/colors.dart b/packages/flutter/lib/src/painting/colors.dart index ec7c99ea2e..8ac89e8f53 100644 --- a/packages/flutter/lib/src/painting/colors.dart +++ b/packages/flutter/lib/src/painting/colors.dart @@ -450,7 +450,7 @@ class ColorSwatch extends Color { return false; return super == other && other is ColorSwatch - && other._swatch == _swatch; + && mapEquals(other._swatch, _swatch); } @override diff --git a/packages/flutter/test/painting/colors_test.dart b/packages/flutter/test/painting/colors_test.dart index c2cbc976c7..d51d757841 100644 --- a/packages/flutter/test/painting/colors_test.dart +++ b/packages/flutter/test/painting/colors_test.dart @@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/painting.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:flutter/material.dart'; const double _doubleColorPrecision = 0.01; @@ -440,4 +441,22 @@ void main() { final Map json = property.toJsonMap(const DiagnosticsSerializationDelegate()); expect(json.containsKey('valueProperties'), isFalse); }); + + test('MaterialColor swatch comparison', () { + const Map sampleMap = { + 0: Colors.lightBlue, + 1: Colors.deepOrange, + 2: Colors.blueGrey, + }; + const MaterialColor first = MaterialColor(0, sampleMap); + const MaterialColor second = MaterialColor(0, sampleMap); + const MaterialColor third = MaterialColor( + 0, { + 0: Colors.lightBlue, + 1: Colors.deepOrange, + 2: Colors.blueGrey, + }); + expect(first == second, true); + expect(first == third, true); + }); }