diff --git a/dio/CHANGELOG.md b/dio/CHANGELOG.md index 491ea0680..9a1ec45f2 100644 --- a/dio/CHANGELOG.md +++ b/dio/CHANGELOG.md @@ -9,6 +9,7 @@ See the [Migration Guide][] for the complete breaking changes list.** - Removes redundant warnings when composing request options on Web. - Fixes boundary inconsistency in `FormData.clone()`. - Support `FileAccessMode` in `Dio.download` and `Dio.downloadUri` to change download file opening mode +- Fix `ListParam` equality by using the `DeepCollectionEquality`. ## 5.7.0 diff --git a/dio/lib/src/parameter.dart b/dio/lib/src/parameter.dart index ef44df948..38ef47565 100644 --- a/dio/lib/src/parameter.dart +++ b/dio/lib/src/parameter.dart @@ -1,3 +1,5 @@ +import 'package:collection/collection.dart'; + import 'options.dart'; /// Indicates a param being used as queries or form data, @@ -26,9 +28,12 @@ class ListParam { identical(this, other) || other is ListParam && runtimeType == other.runtimeType && - value == other.value && + const DeepCollectionEquality().equals(value, other.value) && format == other.format; @override - int get hashCode => value.hashCode ^ format.hashCode; + int get hashCode => Object.hash( + const DeepCollectionEquality().hash(value), + format, + ); } diff --git a/dio/pubspec.yaml b/dio/pubspec.yaml index dc2a19070..3126f410c 100644 --- a/dio/pubspec.yaml +++ b/dio/pubspec.yaml @@ -21,6 +21,7 @@ environment: dependencies: async: ^2.8.2 + collection: ^1.16.0 http_parser: ^4.0.0 meta: ^1.5.0 path: ^1.8.0 diff --git a/dio/test/parameter_test.dart b/dio/test/parameter_test.dart new file mode 100644 index 000000000..f5b32e25f --- /dev/null +++ b/dio/test/parameter_test.dart @@ -0,0 +1,24 @@ +import 'package:dio/dio.dart'; +import 'package:test/test.dart'; + +void main() { + group('ListParam', () { + test('param1 and param2 should be considered equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param2 = const ListParam(['item1', 'item2'], ListFormat.csv); + expect(param1 == param2, isTrue); + }); + + test('param1 and param3 should not be considered equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param3 = const ListParam(['item3', 'item4'], ListFormat.csv); + expect(param1 == param3, isFalse); + }); + + test('Order matters: param1 and param4 should not be equal', () { + final param1 = const ListParam(['item1', 'item2'], ListFormat.csv); + final param4 = const ListParam(['item2', 'item1'], ListFormat.csv); + expect(param1 == param4, isFalse); + }); + }); +}