← All blogs

dust blog

Let Data Models Compare Their Own Values

Manual Dart equality code beside a Dust Eq data class example

Dart lets a class define == and hashCode.

That is fine for small models.

It gets noisy when the model has collection fields.

Dust Eq() keeps that code out of the model file.

Add Eq() to the derive list. Dust compares the runtime type and every field.

Lists and iterables compare by item order. Maps compare by keys and values. Sets compare without order.

Use this when the class is plain data and equality is not custom business logic.

The model stays focused on its fields. The repeated comparison code moves to the generated .g.dart file.

Read the Dust value equality guide.

#Dust #DataClass #Dart #Flutter #CodeGeneration