blob: 55c1d446770057eb0ea3c2b8d8d2758d356ef7e8 [file] [log] [blame]
import 'equatable_config.dart';
import 'equatable_utils.dart';
/// You must define the [EquatableMixin] on the class
/// which you want to make Equatable.
///
/// [EquatableMixin] does the override of the `==` operator as well as
/// `hashCode`.
mixin EquatableMixin {
/// The [List] of `props` (properties) which will be used to determine whether
/// two [Equatables] are equal.
List<Object> get props;
/// If the value is [true], the `toString` method will be overrided to print
/// the equatable `props`.
bool get stringify => false;
@override
bool operator ==(Object other) {
return identical(this, other) ||
other is EquatableMixin &&
runtimeType == other.runtimeType &&
equals(props, other.props);
}
@override
int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props);
@override
String toString() {
switch (stringify) {
case true:
return mapPropsToString(runtimeType, props);
case false:
return '$runtimeType';
default:
return EquatableConfig.stringify == true
? mapPropsToString(runtimeType, props)
: '$runtimeType';
}
}
}