Skip to content

Instantly share code, notes, and snippets.

@yarn-rp
Created July 29, 2023 23:38
Show Gist options
  • Save yarn-rp/372c8cbf32481872831b93269b57e239 to your computer and use it in GitHub Desktop.
Save yarn-rp/372c8cbf32481872831b93269b57e239 to your computer and use it in GitHub Desktop.
Equatable code for overriding == and hashcode
abstract class Equatable {
/// {@macro equatable}
const Equatable();
...
@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);
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment