假设我有一个类:
class Person {
final String name;
final int age;
final DateTime created;
final List<Pet> pets;
}在Dart中,如何列出两个实例之间不同的所有字段,例如“原始”和“更新”的实例?我只需要对每个字段进行浅层(==)检查,包括集合字段(例如pets)。
发布于 2020-11-23 02:11:38
添加此函数
class Person {
String name;
int age;
List<Pet> pets;
void enumerateDifferences(Person other) {
if (this.name != other.name) {
print("Name is different");
} else if (this.age != other.age) {
print("Age is different");
} else if (pets != other.pets) {
//If shallow compare
print("Pets is differenct");
}
}
}https://stackoverflow.com/questions/64957529
复制相似问题