Group Group Group Group Group Group Group Group Group

Use of Equatable in Chapter 13 for non immutable classes

According to the documentation of the Equatable package:

Equatable is designed to only work with immutable objects so all member variables must be final (This is not just a feature of Equatable - overriding a hashCode with a mutable value can break hash-based collections).

However, the book has used the package in non immutable classes, like this:

// ignore: must_be_immutable
class Ingredient extends Equatable {
  int? id;
  int? recipeId;
  final String? name;
  final double? weight;

  Ingredient({this.id, this.recipeId, this.name, this.weight});

  @override
  List<Object?> get props => [recipeId, name, weight];
}

Notice that I had to add ignore: must_be_immutable to make the linter happy.

Should there be a word or two in this regard within the book?

1 Like

Thanks for highlighting this. We’ll take a look and see how we can clarify it.