blob: e10d5b31247c1f221c431e9ca3c3f099a5f850c6 [file] [log] [blame]
import './equatable_utils.dart';
/// A class that helps implement equality
/// without needing to explicitly override == and [hashCode].
/// Equatables override their own == and [hashCode] based on
/// the provided `properties`.
abstract class Equatable {
/// The [List] of `props` (properties) which will be used to determine whether
/// two [Equatables] are equal.
final List props;
/// The constructor takes an optional [List] of `props` (properties) which
/// will be used to determine whether two [Equatables] are equal.
/// If no properties are provided, `props` will be initialized to
/// an empty [List].
Equatable([this.props = const []]);
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is Equatable &&
runtimeType == other.runtimeType &&
equals(props, other.props);
@override
int get hashCode => runtimeType.hashCode ^ mapPropsToHashCode(props);
@override
String toString() => props.isNotEmpty ? props.toString() : super.toString();
}