From a41fb2d2da6702ce322caaf3e6c57aac124e43ef Mon Sep 17 00:00:00 2001 From: Busslina Date: Mon, 21 Apr 2025 20:11:22 +0200 Subject: [PATCH] Allow to conditionally prevent runtimeType check It also export utils in order to be able to customize hashCode --- lib/equatable.dart | 1 + lib/src/equatable_mixin.dart | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/equatable.dart b/lib/equatable.dart index 4f6b3534..2a8bee47 100644 --- a/lib/equatable.dart +++ b/lib/equatable.dart @@ -5,3 +5,4 @@ library equatable; export './src/equatable.dart'; export './src/equatable_config.dart'; export './src/equatable_mixin.dart'; +export './src/equatable_utils.dart'; diff --git a/lib/src/equatable_mixin.dart b/lib/src/equatable_mixin.dart index b69db159..b531ffae 100644 --- a/lib/src/equatable_mixin.dart +++ b/lib/src/equatable_mixin.dart @@ -21,10 +21,14 @@ mixin EquatableMixin { bool operator ==(Object other) { return identical(this, other) || other is EquatableMixin && - runtimeType == other.runtimeType && + (!checkRuntimeTypeOnIdentical || + runtimeType == other.runtimeType) && iterableEquals(props, other.props); } + /// Whether to check runtimeType in order to consider two objects equal. + bool get checkRuntimeTypeOnIdentical => true; + @override int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props);