leonardocustodio / polkadart

Polkadart provides developers the ability to query a node and interact with the Polkadot based chains using Dart.
https://polkadart.dev
Apache License 2.0
39 stars 16 forks source link

Override object equality operator and hashcode #317

Closed Lohann closed 1 year ago

Lohann commented 1 year ago

This PR overrides the operator == and hashCode method of generated files, this is a common practice in dart in order to be able to compare different objects but with same attributes.

example:

class A {
  final int value;

  @override
  bool operator ==(Object other) =>
      identical(this, other) || other is A && other.value == value;

  @override
  int get hashCode => Object.hash(value);
}

class B {
  final BigInt valueA;
  final A valueB;

  @override
  bool operator ==(Object other) =>
      identical(this, other) || other is B && other.valueA == valueA && other.valueB == valueB;

  @override
  int get hashCode => Object.hash(valueA, valueB);
}