Answers for "comparing two objects in dart"

1

how to compare two objects in flutter

E.g.

class Student {
  final String name;
  final int age;

  Student(this.name, this.age);

  @override
  bool operator ==(other) {
    return (other is Student)
        && other.name == name
        && other.age == age;
  }
}

void compareObjects() {
  final s1 = Student('Alice', 25);
  final s2 = Student('Alice', 20);

  print(s1 == s2); // -> true
}
Posted by: Guest on September-08-2021

Code answers related to "comparing two objects in dart"

Code answers related to "Dart"

Browse Popular Code Answers by Language