Dart – copyWith and override comparison operator

void main() {
  var person1 = Person(id: 6, name: "Rene", age: 18);
  var person2 = Person(id: 6, name: "Poul", age: 19);
  var person3 = person1.copyWith(age: 18);
  
  print(person1);
  print(person2);
  print(person3);
  
  print(person1 == person2); //return false
  print(person1 == person3); //return true
}

 class Person {
  int id;
  String name;
  int age;

  Person({required this.id, required this.name, required this.age});
   
  Person copyWith({int? id, String? name, int? age}) => Person(
    id: id ?? this.id,
    name: name ?? this.name,
    age: age ?? this.age,
  );

  @override
  String toString() => 'Person(id: $id, name: $name, age: $age)';
  
  @override
  bool operator ==(Object other) =>
    identical(this, other) ||
    other is Person &&
    runtimeType == other.runtimeType &&
    id == other.id &&
    name == other.name &&
    age == other.age;

  @override
  int get hashCode => id.hashCode ^ name.hashCode ^ age.hashCode;
}