diff --git a/lib/src/chart/base/axis_chart/axis_chart_data.dart b/lib/src/chart/base/axis_chart/axis_chart_data.dart index 8ff0b6743..78ca3007d 100644 --- a/lib/src/chart/base/axis_chart/axis_chart_data.dart +++ b/lib/src/chart/base/axis_chart/axis_chart_data.dart @@ -439,7 +439,8 @@ class FlTitlesData with EquatableMixin { } /// Represents a conceptual position in cartesian (axis based) space. -class FlSpot with EquatableMixin { +@immutable +class FlSpot { /// [x] determines cartesian (axis based) horizontally position /// 0 means most left point of the chart /// @@ -477,13 +478,6 @@ class FlSpot with EquatableMixin { /// Determines if [x] and [y] is not null. bool isNotNull() => !isNull(); - /// Used for equality check, see [EquatableMixin]. - @override - List get props => [ - x, - y, - ]; - /// Lerps a [FlSpot] based on [t] value, check [Tween.lerp]. static FlSpot lerp(FlSpot a, FlSpot b, double t) { if (a == FlSpot.nullSpot) { @@ -499,6 +493,25 @@ class FlSpot with EquatableMixin { lerpDouble(a.y, b.y, t)!, ); } + + /// Two [FlSpot] are equal if their [x] and [y] are equal. + @override + bool operator ==(Object other) { + if (identical(this, other)) return true; + if (other is! FlSpot) { + return false; + } + + if (x.isNaN && y.isNaN && other.x.isNaN && other.y.isNaN) { + return true; + } + + return other.x == x && other.y == y; + } + + /// Override hashCode + @override + int get hashCode => x.hashCode ^ y.hashCode; } /// Responsible to hold grid data, diff --git a/test/chart/base/axis_chart/axis_chart_data_test.dart b/test/chart/base/axis_chart/axis_chart_data_test.dart index dbe5eef6b..98d028ced 100644 --- a/test/chart/base/axis_chart/axis_chart_data_test.dart +++ b/test/chart/base/axis_chart/axis_chart_data_test.dart @@ -65,6 +65,12 @@ void main() { expect(flSpot1 == flSpot2, false); expect(flSpot2 == flSpot2Clone, true); + + expect(nullSpot1 == nullSpot2, true); + + expect(nullSpot2 == nullSpot3, true); + + expect(nullSpot1 == nullSpot3, true); }); test('FlGridData equality test', () { diff --git a/test/chart/data_pool.dart b/test/chart/data_pool.dart index 9dac57ad8..ec64dd6cd 100644 --- a/test/chart/data_pool.dart +++ b/test/chart/data_pool.dart @@ -575,6 +575,10 @@ final FlSpot flSpot1Clone = flSpot1.copyWith(); const FlSpot flSpot2 = FlSpot(4, 2); final FlSpot flSpot2Clone = flSpot2.copyWith(); +const nullSpot1 = FlSpot.nullSpot; +final nullSpot2 = nullSpot1.copyWith(); +const nullSpot3 = FlSpot.nullSpot; + Widget getTitles(double value, TitleMeta meta) => const Text('sallam'); TextStyle getTextStyles(BuildContext context, double value) =>