fix: MaterialColor Swatch Map comparison (#61974)

This commit is contained in:
Ayaan Khan
2020-08-07 04:36:10 +05:30
committed by GitHub
parent 4c3a14c9de
commit 4680ff3a79
2 changed files with 20 additions and 1 deletions

View File

@@ -450,7 +450,7 @@ class ColorSwatch<T> extends Color {
return false;
return super == other
&& other is ColorSwatch<T>
&& other._swatch == _swatch;
&& mapEquals<T, Color>(other._swatch, _swatch);
}
@override

View File

@@ -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<String, Object> json = property.toJsonMap(const DiagnosticsSerializationDelegate());
expect(json.containsKey('valueProperties'), isFalse);
});
test('MaterialColor swatch comparison', () {
const Map<int, MaterialColor> sampleMap = <int, MaterialColor>{
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, <int, MaterialColor>{
0: Colors.lightBlue,
1: Colors.deepOrange,
2: Colors.blueGrey,
});
expect(first == second, true);
expect(first == third, true);
});
}