felangel / equatable

A Dart package that helps to implement value based equality without needing to explicitly override == and hashCode.

Home Page:https://pub.dev/packages/equatable

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why the equatable need to be @immutable?

Katekko opened this issue · comments

I'm asking because I'm trying to extend my class from other class that's not immutable.
image

So I'm wondering why equatable needs to be marked as immutable?

AVOID defining custom equality for mutable classes.
Linter rule: avoid_equals_and_hash_code_on_mutable_classes

When you define ==, you also have to define hashCode. Both of those should take into account the object’s fields. If those fields change then that implies the object’s hash code can change.

Most hash-based collections don’t anticipate that—they assume an object’s hash code will be the same forever and may behave unpredictably if that isn’t true.