DataClass class

Annotate a class to generate equals and hash code functions for it.

An equals function, called _$<class name>Equals is generated for the annotated class. The method takes two arguments self and other and returns true if other is an instance of the annotated class and every property of self is equal to the corresponding property of other by ==.

Similarly a hashCode function, called _$<class name>HashCode is generated for the annotated class. This function computes the hashCode of the class instance passed to it by computing the hashes of each of its properties, using the Object.hashCode property.

Example:

@DataClass()
class Point {
  final int x;
  final int y;
  
  ...
  
  @override
  bool operator ==(Object other) =>
    _$PointEquals(this, other);
    
  @override
  int get hashCode => _$PointHashCode(this);
}

NOTE: Synthetic properties are ignored by both the generated equals and hashCode functions.

To use a different comparator and hash function for a property, annotate it with DataField.

Constructors

DataClass.new()
const

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited