This package solve pain of comparing objects in Dart. By default, even if two objects have the same data, they are not considered equal because Dart looks at where they are stored in memory.
This means you have to write a bunch of annoying, boilerplate code to compare every single property.
This is where the equatable package comes in.
https://pub.dev/packages/equatable
Instead of writing extra code, you just make your class extend Equatable and tell it which properties to check. Here’s a simple example:
class User extends Equatable {
const User({required this.name, required this.age});
final String name;
final int age;
@override
List<Object> get props => [name, age];
}
Now, you can just use user1 == user2 and it will work perfectly. No more manual checks. It saves you time and prevents a lot of bugs, especially with state management. It's a small change with a huge payoff.
This is a good one to know.
this video on the equatable package useful :
Comments
Post a Comment