Created
July 29, 2023 23:38
-
-
Save yarn-rp/372c8cbf32481872831b93269b57e239 to your computer and use it in GitHub Desktop.
Equatable code for overriding == and hashcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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